# --------------------------------------------------------
# Copyright (C) 2004-2025 by EMGU Corporation. All rights reserved.
# 
# Root CMake file for Emgu CV
#
# From the off-tree build directory, invoke:
#   $ cmake <PATH_TO_EMGUCV_ROOT>
#
# --------------------------------------------------------

CMAKE_MINIMUM_REQUIRED(VERSION 3.16)

SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
SET(EMGU_CV_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
INCLUDE (CheckPlatform)

#IF( (WIN32 AND (NOT NETFX_CORE)) OR IS_UBUNTU OR (APPLE AND ("${IOS_ARCH}" STREQUAL "")) )
#IF( (WIN32 AND (NOT NETFX_CORE) AND (NOT IS_ARM64)) OR IS_UBUNTU )
#  SET(EMGU_CV_WITH_DEPTHAI ON CACHE BOOL "Build support for OAK-1 and OAK-D")
#ELSE() 
  SET(EMGU_CV_WITH_DEPTHAI OFF CACHE BOOL "Build support for OAK-1 and OAK-D")
#ENDIF()

#IF(EMGU_CV_WITH_DEPTHAI)
#  # Set defaults
#  set(HUNTER_CONFIGURATION_TYPES "Release" CACHE STRING "Hunter dependencies list of build configurations")
#  
#  include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/HunterGate.cmake")
#  
#  HunterGate(
#    URL "https://github.com/cpp-pm/hunter/archive/v0.24.0.tar.gz"
#    SHA1 "a3d7f4372b1dcd52faa6ff4a3bd5358e1d0e5efd"
#    FILEPATH ${CMAKE_CURRENT_LIST_DIR}/Emgu.CV.Extern/depthai-core/cmake/Hunter/config.cmake # Add depthai-core config (hunter limitation)
#  )
#
#  # Move binary dir if windows, to shorten the path
#  if(WIN32)
#    set(HUNTER_BINARY_DIR "${HUNTER_GATE_ROOT}/_bin" CACHE STRING "Hunter binary directory")
#  endif()
#  #MESSAGE(STATUS: "CMAKE_MODULE_PATH --- ${CMAKE_MODULE_PATH}")
#ENDIF()

IF(EMGU_CV_WITH_DEPTHAI)
  # Always build depthai-core as a static library
  SET(BUILD_SHARED_LIBS_CACHE ${BUILD_SHARED_LIBS})
  SET(BUILD_SHARED_LIBS OFF)
  add_subdirectory(Emgu.CV.Extern/depthai-core EXCLUDE_FROM_ALL)
  SET(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_CACHE})
ENDIF()


PROJECT(emgucv)

if(POLICY CMP0022)
  #cmake_policy(SET CMP0022 NEW)
  SET(CMAKE_POLICY_DEFAULT_CMP0022 NEW)
endif()
if(POLICY CMP0069)
  #cmake_policy(SET CMP0069 NEW)
  SET(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
endif()


#IF(ANDROID)
#include(CheckIPOSupported)
#check_ipo_supported(RESULT supported OUTPUT error)
#if( supported )
#    message(STATUS "IPO / LTO enabled")
#    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
#else()
#    message(STATUS "IPO / LTO not supported: <${error}>")
#endif()
#ENDIF()

IF( WIN32 OR ANDROID OR IOS OR NETFX_CORE)
  SET(EMGU_CV_WITH_FREETYPE ON CACHE BOOL "BUILD FREETYPE")
ELSE() 
  SET(EMGU_CV_WITH_FREETYPE OFF CACHE BOOL "BUILD FREETYPE")
ENDIF()


#IF(WIN32)
#  FIND_PACKAGE(HDF5)
#  IF (TARGET hdf5-static) 
#	get_target_property(HDF5_LIBRARIES hdf5-static IMPORTED_LOCATION_RELEASE)
#	MESSAGE(STATUS "HDF5_DIRS: ${HDF5_DIRS}")
#	MESSAGE(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}")
#	MESSAGE(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}")
#	SET(HDF5_FOUND ON)
#	SET(HDF5_C_LIBRARY ${HDF5_LIBRARIES})
#	message(STATUS "HDF5:   ${HDF5_DIR} (ver ${HDF5_VERSION})")
#	MESSAGE(STATUS "ENV HDF5 : $ENV{HDF5_DIR}/../")
#	MESSAGE(STATUS "HDF5_INCLUDE_DIRS SEARCH PATH : $ENV{HDF5_DIR}/../include")
#	MESSAGE(STATUS "HDF5_C_LIBRARY SEARCH PATH : $ENV{HDF5_DIR}/../lib")
#  else()
#	message(STATUS "HDF5:   NO")
#  endif()	
#ENDIF()

IF(IS_UBUNTU OR IS_RHEL)
  #USE system freetype, do nothing here.
ELSEIF (EMGU_CV_WITH_FREETYPE)
#	ExternalProject_Add(
#		harfbuzz
#		GIT_REPOSITORY https://github.com/harfbuzz/harfbuzz.git
#		GIT_TAG 2.7.2
#		CMAKE_ARGS -DCMAKE_FIND_ROOT_PATH:STRING=${FREETYPE_INSTALL_DIR} -DHB_HAVE_FREETYPE:BOOL=TRUE
#		PREFIX ${CMAKE_CURRENT_BINARY_DIR}/install
#		)
#	ExternalProject_Get_Property(harfbuzz install_dir)
#	SET(HARFBUZZ_INSTALL_DIR ${install_dir})
#    #add_library(harfbuzz STATIC IMPORTED)
#    #set_property(TARGET harfbuzz PROPERTY IMPORTED_LOCATION HARFBUZZ_INSTALL_DIR)
	
	MESSAGE(STATUS "Setting up FREETYPE")
#	find_package(FREETYPE CONFIG REQUIRED)
	find_package(FREETYPE CONFIG)
	if(NOT FREETYPE_FOUND)
		message(STATUS "FREETYPE:   NO")
	else()
		message(STATUS "FREETYPE:   ${FREETYPE_DIR} (ver ${FREETYPE_VERSION})")
		SET(FREETYPE_INCLUDE_DIRS "${FREETYPE_DIR}/../../../include/freetype2")
		SET(FREETYPE_LIBRARY freetype)
		get_target_property(FREETYPE_LIBRARIES freetype IMPORTED_LOCATION_RELEASE)
		#SET(FREETYPE_LIBRARIES ${FREETYPE_LIBRARIES} CACHE STRING "FREETYPE library")
		#SET(FREETYPE_LINK_LIBRARIES ${FREETYPE_LIBRARIES} CACHE STRING "FREETYPE library")
		#SET(FREETYPE_LIBRARIES ${FREETYPE_LIBRARIES})
		SET(FREETYPE_LINK_LIBRARIES ${FREETYPE_LIBRARIES})
		SET(FREETYPE_LINK_LIBRARIES_XXXXX ${FREETYPE_LINK_LIBRARIES})
		MESSAGE(STATUS "FREETYPE_LIBRARIES: ${FREETYPE_LIBRARIES}")
		#SET(FREETYPE_LIBRARIES freetype)
		#SET(FREETYPE_FOUND ON)
	endif()	
#	find_package(HARFBUZZ CONFIG REQUIRED)
	find_package(HARFBUZZ CONFIG) 
	if(NOT HARFBUZZ_FOUND)
		message(STATUS "HARFBUZZ:    NO")
	else()
		message(STATUS "HARFBUZZ:    ${HARFBUZZ_DIR} (ver ${HARFBUZZ_VERSION})")
		SET(HARFBUZZ_INCLUDE_DIRS "${HARFBUZZ_DIR}/../../../include/harfbuzz")
		get_target_property(HARFBUZZ_LIBRARY harfbuzz::harfbuzz IMPORTED_LOCATION_RELEASE)
		
		#SET(HARFBUZZ_LIBRARIES ${HARFBUZZ_LIBRARY} CACHE STRING "HARFBUZZ library")
		#SET(HARFBUZZ_LINK_LIBRARIES ${HARFBUZZ_LIBRARY} CACHE STRING "HARFBUZZ library")
		SET(HARFBUZZ_LIBRARIES ${HARFBUZZ_LIBRARY})
		SET(HARFBUZZ_LINK_LIBRARIES ${HARFBUZZ_LIBRARY})
		SET(HARFBUZZ_LINK_LIBRARIES_XXXXX ${HARFBUZZ_LINK_LIBRARIES})
		MESSAGE(STATUS "HARFBUZZ_LIBRARIES: ${HARFBUZZ_LIBRARIES}")
		#IF (WIN32)
		#	SET(HARFBUZZ_LIBRARY "${HARFBUZZ_DIR}/../../harfbuzz.lib")
		#ELSE()
		#	SET(HARFBUZZ_LIBRARY "harfbuzz")
		#ENDIF()
		#message(STATUS "HARFBUZZ_DIR: ${HARFBUZZ_DIR}")
		
		#message(STATUS "harfbuzz_INCLUDE_DIRS: ${harfbuzz_INCLUDE_DIRS}")
		#message(STATUS "HARFBUZZ_INCLUDE_DIRS: ${HARFBUZZ_INCLUDE_DIRS}")
		#SET(HARFBUZZ_FOUND ON)
		#MESSAGE(STATUS "Adding include_directory: ${HARFBUZZ_DIR}/../../../include/harfbuzz")
		include_directories(${HARFBUZZ_INCLUDE_DIRS})
	endif()
#  ELSE()
#  ENDIF()
ELSE()
  SET(FREETYPE_LIBRARY "")
ENDIF()

IF(WITH_OPENVINO)
  find_package(TBB CONFIG)
  find_package(OpenVINO CONFIG)
  find_package(ngraph CONFIG)
ENDIF()

IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
  SET(CMAKE_C_FLAGS_RELEASE "-flto ${CMAKE_C_FLAGS_RELEASE}")
  SET(CMAKE_CXX_FLAGS_RELEASE "-flto ${CMAKE_CXX_FLAGS_RELEASE}")
  SET(CMAKE_C_FLAGS_DEBUG "-flto ${CMAKE_C_FLAGS_DEBUG}")
  SET(CMAKE_CXX_FLAGS_DEBUG "-flto ${CMAKE_CXX_FLAGS_DEBUG}")
  SET(CMAKE_EXE_LINKER_FLAGS "-flto ${CMAKE_EXE_LINKER_FLAGS}")
  SET(CMAKE_SHARED_LINKER_FLAGS "-flto ${CMAKE_SHARED_LINKER_FLAGS}")
  #SET(CMAKE_STATIC_LINKER_FLAGS "-flto ${CMAKE_STATIC_LINKER_FLAGS}")

  set(CMAKE_AR "emcc")
  set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc")
  set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> -flto -r -o <TARGET> <LINK_FLAGS> <OBJECTS>")
  set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> -flto -r -o <TARGET> <LINK_FLAGS> <OBJECTS>")

ENDIF()

#IF( NOT (NETFX_CORE OR ANDROID OR IOS ) )
  
  #  IF (NOT WIN32)
  #    SET(CMAKE_C_FLAGS_RELEASE "-fPIC ${CMAKE_C_FLAGS_RELEASE}")
  #    SET(CMAKE_CXX_FLAGS_RELEASE "-fPIC ${CMAKE_CXX_FLAGS_RELEASE}")
  #    SET(CMAKE_C_FLAGS_DEBUG "-fPIC ${CMAKE_C_FLAGS_DEBUG}")
  #    SET(CMAKE_CXX_FLAGS_DEBUG "-fPIC ${CMAKE_CXX_FLAGS_DEBUG}")
  #    SET(CMAKE_EXE_LINKER_FLAGS "-fPIC ${CMAKE_EXE_LINKER_FLAGS}")
  #    SET(CMAKE_SHARED_LINKER_FLAGS "-fPIC ${CMAKE_SHARED_LINKER_FLAGS}")
  #  ENDIF()
  #IF (WIN32)
  #  SET(BUILD_SHARED_LIBS_CACHE ${BUILD_SHARED_LIBS})
  #  SET(BUILD_SHARED_LIBS OFF)
  #  SET(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON)
    
    #ADD_SUBDIRECTORY(vtk) # always build vtk as static library
	    
    #SET(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_CACHE})
  #ENDIF()
  #  IF (NOT WIN32)
  #    SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE_CACHE} )
  #    SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE_CACHE})
  #  ENDIF()
#ENDIF()

SET(OPENCV_SUBFOLDER ${CMAKE_CURRENT_SOURCE_DIR}/opencv)
SET(OPENCV_CONTRIB_SUBFOLDER ${CMAKE_CURRENT_SOURCE_DIR}/opencv_contrib)
SET(OPENCV_EXTRA_SUBFOLDER ${CMAKE_CURRENT_SOURCE_DIR}/opencv_extra)


  
SET(CSC_PREFERRED_VERSION "4.0")
IF((NOT NETFX_CORE) AND MSVC) 
  #SET CSC 3.5 as the prefered compiler for EMGU CV
  SET(CSC_TARGET_FRAMEWORK "3.5" CACHE STRING "C#  target framework")
ELSE()
  #SET CSC 4.5 (in the .Net framework 4.0 folder) as the prefered compiler for EMGU CV
  SET(CSC_TARGET_FRAMEWORK "" CACHE STRING "C# target framework")
ENDIF()
  
FIND_PACKAGE(CSharp REQUIRED)
INCLUDE (CSharpMacros)

IF (NOT (DOTNET_FOUND))
  IF (IS_UBUNTU)
    MESSAGE(FATAL_ERROR "dotnet sdk is required to build Emgu CV on Ubuntu, please follow the instructions to install dotnet sdk on Ubuntu: https://dotnet.microsoft.com/download/linux-package-manager/ubuntu18-04/sdk-current")  
  ELSEIF(IS_DEBIAN OR IS_RHEL)
    MESSAGE(FATAL_ERROR "dotnet sdk is required to build Emgu CV")  
  ENDIF()
ENDIF()

INCLUDE (CheckTargetArch)
INCLUDE (OpenCVVersion)

IF(WIN32)
  INCLUDE (FindCodeSign)
ENDIF()

#SET(LIBRARY_3RDPARTY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib/3rdParty)


# ----------------------------------------------------------------------------
#  Check if 32bit or 64-bit
# ----------------------------------------------------------------------------
CHECK_TARGET_ARCH()

SET(EMGUCV_ARCH ${TARGET_ARCH_NAME})
MESSAGE(STATUS "Building for ${EMGUCV_ARCH}")

IF ( TARGET_ARCH_64 )
  IF (TARGET_ARM)
    SET(NUGET_NATIVE_PLATFORM_ID_ARCH "arm64")
  ELSE()
    SET(NUGET_NATIVE_PLATFORM_ID_ARCH "x64")
  ENDIF()
ELSE()
  IF (TARGET_ARM)
    SET(NUGET_NATIVE_PLATFORM_ID_ARCH "arm")
  ELSE()
    SET(NUGET_NATIVE_PLATFORM_ID_ARCH "x86")
  ENDIF()
ENDIF()

IF(WIN32 AND CV_ICC)
  #  SET(CV_ICC_ADDITIONAL_FLAGS_RELEASE "/O3 /QaxCORE-AVX2,AVX,SSE4.1,SSE3 /Qparallel /Qopt-report:1 /Qopt-report-phase:vec /Qopt-report-phase:par /Qopt-report-file:stderr /Qipo /Qunroll-aggressive")
  SET(CV_ICC_ADDITIONAL_FLAGS_RELEASE "/O3 /QaxCORE-AVX2,AVX,SSE4.1,SSE3 /Qparallel /Qopt-report:1 /Qopt-report-phase:vec /Qopt-report-phase:par /Qipo /Qrestrict /Ot")
  STRING(REGEX REPLACE "/O2" ${CV_ICC_ADDITIONAL_FLAGS_RELEASE} CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
  STRING(REGEX REPLACE "/O2" ${CV_ICC_ADDITIONAL_FLAGS_RELEASE} CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
  SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:\"libcmt\"")
  SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NODEFAULTLIB:\"libcmt\"")
  set(EMGUCV_PLATFORM_TOOLSET "Intel C++ Compiler 19.1" CACHE STRING "Platform toolset for Visual Studio")
ENDIF()

IF(WIN32 AND NOT MINGW)
  SET(NETFX_CORE OFF CACHE BOOL "Build Windows Store App")
  #  IF(NETFX_CORE)
  #    add_definitions(-DWINAPI_FAMILY=WINAPI_FAMILY_APP -DWINVER=0x0602 -D_WIN32_WINNT=0x0602) 
  #	add_definitions(-D_UNICODE)
  #  ENDIF()
ENDIF()

IF(IOS)
  SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/libs)
ELSE()
  SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/libs)
ENDIF()

IF(NOT WIN32)
  SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/libs)
ENDIF()

MESSAGE(STATUS "<<<< EMGUCV_ARCH: ${EMGUCV_ARCH} >>>>")
MESSAGE(STATUS "<<<< CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME} >>>>")
MESSAGE(STATUS "<<<< CMAKE_SYSTEM_VERSION: ${CMAKE_SYSTEM_VERSION} >>>>")
MESSAGE(STATUS "<<<< CMAKE_GENERATOR: ${CMAKE_GENERATOR} >>>>")
MESSAGE(STATUS "<<<< CMAKE_HOST_SYSTEM_PROCESSOR: ${CMAKE_HOST_SYSTEM_PROCESSOR} >>>>")
MESSAGE(STATUS "<<<< CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR} >>>>")
IF(APPLE)
  MESSAGE(STATUS "<<<< CMAKE_APPLE_SILICON_PROCESSOR: ${CMAKE_APPLE_SILICON_PROCESSOR} >>>>")
ENDIF()
IF(IPHONESIMULATOR)
  MESSAGE(STATUS "<<<< IPHONESIMULATOR: ${IPHONESIMULATOR} >>>>")
ENDIF()
IF(IPHONEOS)
  MESSAGE(STATUS "<<<< IPHONEOS: ${IPHONEOS} >>>>")
ENDIF()


IF(ANDROID)
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/android/${ANDROID_ABI}")
ELSEIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/webgl")
ELSEIF(WIN32)
  MESSAGE(STATUS "<<<< MSVC_C_ARCHITECTURE_ID: ${MSVC_C_ARCHITECTURE_ID} >>>>") 
  IF ("${EMGUCV_ARCH}" STREQUAL "win64")
    IF("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore" AND (CMAKE_SYSTEM_VERSION MATCHES 10.0))
	  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/win10-x64/native")
    ELSE()
      SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/win-x64/native")
    ENDIF()
  ELSEIF("${EMGUCV_ARCH}" STREQUAL "win-arm64")
    IF("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore" AND (CMAKE_SYSTEM_VERSION MATCHES 10.0))
	  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/win10-arm64/native")
    ELSE()
	  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/win-arm64/native")
    ENDIF()
  ELSEIF("${EMGUCV_ARCH}" STREQUAL "win-arm")
    IF("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore" AND (CMAKE_SYSTEM_VERSION MATCHES 10.0))
	  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/win10-arm/native")
    ELSE()
	  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/win-arm/native")
    ENDIF()
  ELSE()
    IF("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore" AND (CMAKE_SYSTEM_VERSION MATCHES 10.0))
	#IF("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
    #  IF(CMAKE_SYSTEM_VERSION MATCHES 10.0)
	  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/win10-x86/native")    
	ELSE()
	  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/win-x86/native")
	ENDIF()
  ENDIF()
  #MESSAGE(STATUS ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
  #MESSAGE(STATUS ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> EMGUCV_ARCH: ${EMGUCV_ARCH}")
  #MESSAGE(STATUS ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER: ${UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER}")
ELSEIF(APPLE AND NOT IOS)
  IF ("${EMGUCV_ARCH}" STREQUAL "arm64")
    SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/osx/native/arm64")
  ELSE()
    SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/osx/native/x64")
  ENDIF()
ELSEIF("${EMGUCV_ARCH}" STREQUAL "ubuntu_x64")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/ubuntu-x64/native")
ELSEIF("${EMGUCV_ARCH}" STREQUAL "ubuntu_x86")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/ubuntu-x86/native")
ELSEIF("${EMGUCV_ARCH}" STREQUAL "ubuntu_arm64")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/ubuntu-arm64/native")
ELSEIF("${EMGUCV_ARCH}" STREQUAL "ubuntu_arm")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/ubuntu-arm/native")
ELSEIF("${EMGUCV_ARCH}" STREQUAL "rhel_x64")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/rhel-x64/native")
ELSEIF("${EMGUCV_ARCH}" STREQUAL "rhel_x86")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/rhel-x86/native")
ELSEIF("${EMGUCV_ARCH}" STREQUAL "rhel_arm64")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/rhel-arm64/native")
ELSEIF("${EMGUCV_ARCH}" STREQUAL "rhel_arm")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/rhel-arm/native")
ELSEIF("${EMGUCV_ARCH}" STREQUAL "debian_arm")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/linux-arm/native")
  ELSEIF("${EMGUCV_ARCH}" STREQUAL "debian_arm64")
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/runtimes/linux-arm64/native")
ELSEIF("${EMGUCV_ARCH}" STREQUAL "arm64")
  IF(IPHONEOS)
    SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/iphoneos_arm64")
  ELSEIF(IPHONESIMULATOR)
    SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/simulator_arm64")
  ELSE()
    SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/arm64")
  ENDIF()
ELSEIF("${EMGUCV_ARCH}" STREQUAL "arm")
  IF(IPHONEOS)
    SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/iphoneos_arm")
  ELSEIF(IPHONESIMULATOR)
    SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/simulator_arm")
  ELSE()
    SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/arm")
  ENDIF()
ELSE()
  SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "")
ENDIF()

SET(UNMANAGED_LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/libs${UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER}")
IF(ANDROID)
  SET(LIBRARY_OUTPUT_PATH ${UNMANAGED_LIBRARY_OUTPUT_PATH})
ENDIF()
FILE(MAKE_DIRECTORY ${UNMANAGED_LIBRARY_OUTPUT_PATH})

SET(UNMANAGED_DLL_EXTRA)

MACRO(CHECK_BINARY_EXIST folder pattern property_name second_check)
  #IF("${UNMANAGED_LIBRARY_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/${folder}")
  #  SET(${property_name} ON)
  #ELSE()
    FILE(GLOB DLL_LIST "${CMAKE_CURRENT_SOURCE_DIR}/${folder}/${pattern}")
    LIST(LENGTH DLL_LIST DLL_LIST_LENGTH)
    IF(DLL_LIST_LENGTH GREATER 0)
      LIST(APPEND UNMANAGED_DLL_EXTRA ${DLL_LIST})
      MESSAGE(STATUS "Including the following files in package: ${DLL_LIST}")
      INSTALL(
	   FILES
	   ${DLL_LIST}
	   DESTINATION ${folder}
	   COMPONENT emgucv_binary
	   )  
      SET(${property_name} ON)
    ELSE()
      SET(${property_name} ${second_check})
    ENDIF()
  #ENDIF()
  #MESSAGE(STATUS "Property - ${property_name}: ${${property_name}}")
  IF(${${property_name}})
    MESSAGE(STATUS "${property_name}: ${${property_name}}")
  ENDIF()
ENDMACRO()

#MESSAGE(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
SET(IS_IOS_BUILD OFF)
SET(IS_MAC_CATALYST_BUILD OFF)
SET(IS_MAC_CATALYST_ARM64_BUILD OFF)
SET(IS_MAC_CATALYST_X86_64_BUILD OFF)  
SET(IS_MAC_BUILD OFF)
SET(IS_MAC_ARM64_BUILD OFF)
SET(IS_MAC_X86_64_BUILD OFF)

IF(MAC_CATALYST)
  SET(IS_MAC_CATALYST_BUILD ON)
  MESSAGE(STATUS "IS_MAC_CATALYST_BUILD: ${IS_MAC_CATALYST_BUILD}")

  IF (IS_MAC_CATALYST_BUILD AND ("${EMGUCV_ARCH}" STREQUAL "arm64"))
    SET(IS_MAC_CATALYST_ARM64_BUILD ON)
	MESSAGE(STATUS "IS_MAC_CATALYST_ARM64_BUILD: ${IS_MAC_CATALYST_ARM64_BUILD}")
  ENDIF()

  IF (IS_MAC_CATALYST_BUILD AND ("${EMGUCV_ARCH}" STREQUAL "x86_64"))
    SET(IS_MAC_CATALYST_X86_64_BUILD ON)
	MESSAGE(STATUS "IS_MAC_CATALYST_X86_64_BUILD: ${IS_MAC_CATALYST_X86_64_BUILD}")
  ENDIF()
ELSEIF(IOS)
  SET(IS_IOS_BUILD ON)
  MESSAGE(STATUS "IS_IOS_BUILD: ${IS_IOS_BUILD}")
  
  SET(IS_IOS_I386_BUILD OFF)
  IF(IS_IOS_BUILD AND ("${IOS_ARCH}" STREQUAL "i386"))
    SET(IS_IOS_I386_BUILD ON)
    MESSAGE(STATUS "IS_IOS_I386_BUILD: ${IS_IOS_I386_BUILD}")
  ENDIF()
  #CHECK_BINARY_EXIST("libs/iOS" "libcvextern_i386.a" HAVE_IOS_I386 ${IS_IOS_I386_BUILD})
  
  SET(IS_IOS_X86_64_BUILD OFF)
  IF(IS_IOS_BUILD AND ("${IOS_ARCH}" STREQUAL "x86_64"))
    SET(IS_IOS_X86_64_BUILD ON)
    MESSAGE(STATUS "IS_IOS_X86_64_BUILD: ${IS_IOS_X86_64_BUILD}")
  ENDIF()
  #CHECK_BINARY_EXIST("libs/iOS" "libcvextern_x86_64.a" HAVE_IOS_X86_64 ${IS_IOS_X86_64_BUILD})
  
  SET(IS_IOS_ARMV7S_BUILD OFF)
  IF(IS_IOS_BUILD AND ("${IOS_ARCH}" STREQUAL "armv7s"))
    SET(IS_IOS_ARMV7S_BUILD ON)
    MESSAGE(STATUS "IS_IOS_ARMV7S_BUILD: ${IS_IOS_ARMV7S_BUILD}")
  ENDIF()
  #CHECK_BINARY_EXIST("libs/iOS" "libcvextern_armv7s.a" HAVE_IOS_ARMV7S ${IS_IOS_ARMV7S_BUILD})
  
  SET(IS_IOS_ARMV7_BUILD OFF)
  IF(IS_IOS_BUILD AND ("${IOS_ARCH}" STREQUAL "armv7"))
    SET(IS_IOS_ARMV7_BUILD ON)
    MESSAGE(STATUS "IS_IOS_ARMV7_BUILD: ${IS_IOS_ARMV7_BUILD}")
  ENDIF()
  #CHECK_BINARY_EXIST("libs/iOS" "libcvextern_armv7.a" HAVE_IOS_ARMV7 ${IS_IOS_ARMV7_BUILD})
  
  SET(IS_IOS_ARM64_BUILD OFF)
  IF(IS_IOS_BUILD AND ("${IOS_ARCH}" STREQUAL "arm64"))
    SET(IS_IOS_ARM64_BUILD ON)
    MESSAGE(STATUS "IS_IOS_ARM64_BUILD: ${IS_IOS_ARM64_BUILD}")
  ENDIF()
  #CHECK_BINARY_EXIST("libs/iOS" "libcvextern_arm64.a" HAVE_IOS_ARM64 ${IS_IOS_ARM64_BUILD})
ELSEIF(APPLE)
  SET(IS_MAC_BUILD ON)
  MESSAGE(STATUS "IS_MAC_BUILD: ${IS_MAC_BUILD}")

  IF ("${EMGUCV_ARCH}" STREQUAL "arm64")
    SET(IS_MAC_ARM64_BUILD ON)
	MESSAGE(STATUS "IS_MAC_ARM64_BUILD: ${IS_MAC_ARM64_BUILD}")
  ELSEIF ("${EMGUCV_ARCH}" STREQUAL "x86_64")
    SET(IS_MAC_X86_64_BUILD ON)
	MESSAGE(STATUS "IS_MAC_X86_64_BUILD: ${IS_MAC_X86_64_BUILD}")
  ENDIF()

ENDIF()

CHECK_BINARY_EXIST("libs/iOS" "libcvextern_iphoneos.a" HAVE_IOS_DEVICE ${IS_IOS_BUILD})
CHECK_BINARY_EXIST("libs/iOS" "libcvextern_simulator.a" HAVE_IOS_SIMULATOR ${IS_IOS_BUILD})
CHECK_BINARY_EXIST("libs/iOS" "libcvextern_universal.a" HAVE_IOS_UNIVERSAL ${IS_IOS_BUILD})
IF (HAVE_IOS_DEVICE OR HAVE_IOS_SIMULATOR OR HAVE_IOS_UNIVERSAL)
  SET(HAVE_IOS ON)
  MESSAGE(STATUS "HAVE_IOS: ${HAVE_IOS}")
ELSE()
  SET(HAVE_IOS OFF)
ENDIF()
CHECK_BINARY_EXIST("libs/Build/Emgu.CV.runtime.maui.ios/AnyCPU/Release/net${DOTNET_VERSION_MAJOR}.0-ios" "Emgu.CV.runtime.maui.ios.dll" HAVE_MAUI_IOS ${HAVE_IOS})

CHECK_BINARY_EXIST("libs/iOS" "libcvextern_catalyst_arm64.a" HAVE_MAC_CATALYST_ARM64 ${IS_MAC_CATALYST_ARM64_BUILD})
CHECK_BINARY_EXIST("libs/iOS" "libcvextern_catalyst_x86_64.a" HAVE_MAC_CATALYST_X86_64 ${IS_MAC_CATALYST_X86_64_BUILD})
IF (HAVE_MAC_CATALYST_ARM64 OR HAVE_MAC_CATALYST_X86_64)
  SET(HAVE_MAC_CATALYST ON)
  MESSAGE(STATUS "HAVE_MAC_CATALYST: ${HAVE_MAC_CATALYST}")
ELSE()
  SET(HAVE_MAC_CATALYST OFF)
ENDIF()
CHECK_BINARY_EXIST("libs/Build/Emgu.CV.runtime.maui.macos/AnyCPU/Release/net${DOTNET_VERSION_MAJOR}.0-maccatalyst" "Emgu.CV.runtime.maui.macos.dll" HAVE_MAUI_MAC ${HAVE_MAC_CATALYST})


#IF(NOT HAVE_IOS)
#  IF(HAVE_IOS_I386 OR HAVE_IOS_X86_64 OR HAVE_IOS_ARMV7S OR HAVE_IOS_ARMV7 OR HAVE_IOS_ARM64)
#    SET(HAVE_IOS ON) 
#  ENDIF()
#ENDIF()

#SET(HAVE_IOS_ALL_ARCH OFF)
#IF(HAVE_IOS_I386 AND HAVE_IOS_X86_64 AND HAVE_IOS_ARMV7S AND HAVE_IOS_ARMV7 AND HAVE_IOS_ARM64)
#  SET(HAVE_IOS_ALL_ARCH ON) 
#ENDIF()
#IF(HAVE_IOS_ALL_ARCH)
#  MESSAGE(STATUS "HAVE_IOS_ALL_ARCH: ${HAVE_IOS_ALL_ARCH}")
#ENDIF()

#IF(HAVE_IOS)
#  MESSAGE(STATUS "HAVE_IOS: ON")
#ENDIF()


SET(IS_MACOS_BUILD OFF)
IF(APPLE AND (NOT IOS))
  SET(IS_MACOS_BUILD ON)
  MESSAGE(STATUS "IS_MACOS_BUILD: ${IS_MACOS_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/osx/native" "lib*.dylib" HAVE_MACOS ${IS_MACOS_BUILD})

SET(IS_ANDROID_ARM64_V8A_BUILD OFF)
IF(ANDROID AND ("${ANDROID_ABI}" STREQUAL "arm64-v8a"))
  SET(IS_ANDROID_ARM64_V8A_BUILD ON)
  MESSAGE(STATUS "IS_ANDROID_ARM64_V8A_BUILD: ${IS_ANDROID_ARM64_V8A_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/android/arm64-v8a" "*.so" HAVE_ANDROID_ARM64_V8A ${IS_ANDROID_ARM64_V8A_BUILD})

#SET(IS_ANDROID_ARMEABI_BUILD OFF)
#IF(ANDROID AND ("${ANDROID_ABI}" STREQUAL "armeabi"))
#  SET(IS_ANDROID_ARMEABI_BUILD ON)
#  MESSAGE(STATUS "IS_ANDROID_ARMEABI_BUILD: ${IS_ANDROID_ARMEABI_BUILD}")
#ENDIF()
#CHECK_BINARY_EXIST("libs/android/armeabi" "*.so" HAVE_ANDROID_ARMEABI ${IS_ANDROID_ARMEABI_BUILD})

SET(IS_ANDROID_ARMEABI_V7A_BUILD OFF)
IF(ANDROID AND ("${ANDROID_ABI}" STREQUAL "armeabi-v7a"))
  SET(IS_ANDROID_ARMEABI_V7A_BUILD ON)
  MESSAGE(STATUS "IS_ANDROID_ARMEABI_V7A_BUILD: ${IS_ANDROID_ARMEABI_V7A_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/android/armeabi-v7a" "*.so" HAVE_ANDROID_ARMEABI_V7A ${IS_ANDROID_ARMEABI_V7A_BUILD})

SET(IS_ANDROID_X86_BUILD OFF)
IF(ANDROID AND ("${ANDROID_ABI}" STREQUAL "x86"))
  SET(IS_ANDROID_X86_BUILD ON)
  MESSAGE(STATUS "IS_ANDROID_X86_BUILD: ${IS_ANDROID_X86_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/android/x86" "*.so" HAVE_ANDROID_X86 ${IS_ANDROID_X86_BUILD})

SET(IS_ANDROID_X86_64_BUILD OFF)
IF(ANDROID AND ("${ANDROID_ABI}" STREQUAL "x86_64"))
  SET(IS_ANDROID_X86_64_BUILD ON)
  MESSAGE(STATUS "IS_ANDROID_X86_64_BUILD: ${IS_ANDROID_X86_64_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/android/x86_64" "*.so" HAVE_ANDROID_X86_64 ${IS_ANDROID_X86_64_BUILD})

SET(HAVE_ANDROID OFF)
IF(HAVE_ANDROID_ARM64_V8A OR HAVE_ANDROID_ARMEABI_V7A OR HAVE_ANDROID_X86 OR HAVE_ANDROID_X86_64)
  SET(HAVE_ANDROID ON) 
  MESSAGE(STATUS "HAVE_ANDROID: ${HAVE_ANDROID}")
ENDIF()

SET(HAVE_ANDROID_ALL_ARCH OFF)
IF(HAVE_ANDROID_ARM64_V8A AND HAVE_ANDROID_ARMEABI_V7A AND HAVE_ANDROID_X86 AND HAVE_ANDROID_X86_64)
  SET(HAVE_ANDROID_ALL_ARCH ON)
  MESSAGE(STATUS "HAVE_ANDROID_ALL_ARCH: ${HAVE_ANDROID_ALL_ARCH}")
ENDIF()



SET(IS_WINSTORE_10_X86_BUILD OFF)
IF( ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore") AND (CMAKE_SYSTEM_VERSION MATCHES 10.0) AND ("${EMGUCV_ARCH}" STREQUAL "win32") )
  SET(IS_WINSTORE_10_X86_BUILD ON)
  MESSAGE(STATUS "IS_WINSTORE_10_X86_BUILD: ${IS_WINSTORE_10_X86_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/win10-x86/native" "*.dll" HAVE_WINSTORE_10_X86 ${IS_WINSTORE_10_X86_BUILD})

SET(IS_WINSTORE_10_X64_BUILD OFF)
IF( ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore") AND (CMAKE_SYSTEM_VERSION MATCHES 10.0) AND ("${EMGUCV_ARCH}" STREQUAL "win64") )
  SET(IS_WINSTORE_10_X64_BUILD ON)
  MESSAGE(STATUS "IS_WINSTORE_10_X64_BUILD: ${IS_WINSTORE_10_X64_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/win10-x64/native" "*.dll" HAVE_WINSTORE_10_X64 ${IS_WINSTORE_10_X64_BUILD})

SET(IS_WINSTORE_10_ARM_BUILD OFF)
IF(("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore") AND (CMAKE_SYSTEM_VERSION MATCHES 10.0) AND ("${EMGUCV_ARCH}" STREQUAL "arm"))
  SET(IS_WINSTORE_10_ARM_BUILD ON)
  MESSAGE(STATUS "IS_WINSTORE_10_ARM_BUILD: ${IS_WINSTORE_10_ARM_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/win10-arm/native" "*.dll" HAVE_WINSTORE_10_ARM ${IS_WINSTORE_10_ARM_BUILD})

SET(IS_WINSTORE_10_ARM64_BUILD OFF)
IF(("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore") AND (CMAKE_SYSTEM_VERSION MATCHES 10.0) AND ("${EMGUCV_ARCH}" STREQUAL "arm64"))
  SET(IS_WINSTORE_10_ARM64_BUILD ON)
  MESSAGE(STATUS "IS_WINSTORE_10_ARM64_BUILD: ${IS_WINSTORE_10_ARM64_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/win10-arm64/native" "*.dll" HAVE_WINSTORE_10_ARM64 ${IS_WINSTORE_10_ARM64_BUILD})

SET(IS_WINDESKTOP_X86_BUILD OFF)
IF (WIN32 AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") AND ("${EMGUCV_ARCH}" STREQUAL "win32") AND (NOT ANDROID)) 
  SET (IS_WINDESKTOP_X86_BUILD ON)
  MESSAGE(STATUS "IS_WINDESKTOP_X86_BUILD: ${IS_WINDESKTOP_X86_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/win-x86/native" "*.dll" HAVE_WINDESKTOP_X86 ${IS_WINDESKTOP_X86_BUILD})

SET (IS_WINDESKTOP_X64_BUILD OFF)
IF (WIN32 AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") AND ("${EMGUCV_ARCH}" STREQUAL "win64") AND (NOT ANDROID)) 
  SET (IS_WINDESKTOP_X64_BUILD ON)
  MESSAGE(STATUS "IS_WINDESKTOP_X64_BUILD: ${IS_WINDESKTOP_X64_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/win-x64/native" "*.dll" HAVE_WINDESKTOP_X64 ${IS_WINDESKTOP_X64_BUILD})

SET (IS_WINDESKTOP_ARM64_BUILD OFF)
IF (WIN32 AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") AND ("${EMGUCV_ARCH}" STREQUAL "arm64") AND (NOT ANDROID)) 
  SET (IS_WINDESKTOP_ARM64_BUILD ON)
  MESSAGE(STATUS "IS_WINDESKTOP_ARM64_BUILD: ${IS_WINDESKTOP_ARM64_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/win-arm64/native" "*.dll" HAVE_WINDESKTOP_ARM64 ${IS_WINDESKTOP_ARM64_BUILD})

SET(HAVE_WINDESKTOP OFF)
IF (HAVE_WINDESKTOP_X86 OR HAVE_WINDESKTOP_X64 OR HAVE_WINDESKTOP_ARM64)
  SET(HAVE_WINDESKTOP ON)
ENDIF()

SET(IS_DEBIAN_ARM_BUILD OFF)
SET(IS_DEBIAN_ARM64_BUILD OFF)
IF (IS_DEBIAN) 
  IF(IS_ARM)
    SET (IS_DEBIAN_ARM_BUILD ON)
    MESSAGE(STATUS "IS_DEBIAN_ARM_BUILD: ${IS_DEBIAN_ARM_BUILD}")
  ELSE(IS_ARM64)
    SET (IS_DEBIAN_ARM64_BUILD ON)
    MESSAGE(STATUS "IS_DEBIAN_ARM64_BUILD: ${IS_DEBIAN_ARM64_BUILD}")
  ENDIF() 
ENDIF()

SET (IS_DEBIAN_BUILD OFF)
IF(IS_DEBIAN_ARM_BUILD OR IS_DEBIAN_ARM64_BUILD)
  SET (IS_DEBIAN_BUILD ON)
ENDIF()


CHECK_BINARY_EXIST("libs/runtimes/linux-arm/native" "*.so" HAVE_LINUX_ARM ${IS_DEBIAN_ARM_BUILD})
CHECK_BINARY_EXIST("libs/runtimes/linux-arm64/native" "*.so" HAVE_LINUX_ARM64 ${IS_DEBIAN_ARM64_BUILD})

IF(IS_DEBIAN_ARM_BUILD)
  SET(NUGET_NATIVE_PLATFORM_ID_DEBIAN "linux-${NUGET_NATIVE_PLATFORM_ID_ARCH}")
  MESSAGE(STATUS "NUGET_NATIVE_PLATFORM_ID_DEBIAN: ${NUGET_NATIVE_PLATFORM_ID_DEBIAN}") 
ELSE()
  SET(NUGET_NATIVE_PLATFORM_ID_DEBIAN "linux-arm")  
ENDIF()
STRING(TOLOWER "${NUGET_NATIVE_PLATFORM_ID_DEBIAN}" NUGET_NATIVE_PLATFORM_ID_DEBIAN)

SET(IS_UBUNTU_X86_BUILD OFF)
IF (("${TARGET_ARCH_NAME}" STREQUAL "ubuntu_x86"))
  SET(IS_UBUNTU_X86_BUILD ON)
  MESSAGE(STATUS "IS_UBUNTU_X86_BUILD: ${IS_UBUNTU_X86_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/ubuntu-x86/native" "*.so" HAVE_UBUNTU_X86 ${IS_UBUNTU_X86_BUILD})

SET(IS_UBUNTU_X64_BUILD OFF)
IF (("${TARGET_ARCH_NAME}" STREQUAL "ubuntu_x64"))
  SET(IS_UBUNTU_X64_BUILD ON)
  MESSAGE(STATUS "IS_UBUNTU_X64_BUILD: ${IS_UBUNTU_X64_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/ubuntu-x64/native" "*.so" HAVE_UBUNTU_X64 ${IS_UBUNTU_X64_BUILD})

SET(IS_UBUNTU_ARM64_BUILD OFF)
IF (("${TARGET_ARCH_NAME}" STREQUAL "ubuntu_arm64"))
  SET(IS_UBUNTU_ARM64_BUILD ON)
  MESSAGE(STATUS "IS_UBUNTU_ARM64_BUILD: ${IS_UBUNTU_ARM64_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/ubuntu-arm64/native" "*.so" HAVE_UBUNTU_ARM64 ${IS_UBUNTU_ARM64_BUILD})

SET(IS_RHEL_X64_BUILD OFF)
IF (("${TARGET_ARCH_NAME}" STREQUAL "rhel_x64"))
  SET(IS_RHEL_X64_BUILD ON)
  MESSAGE(STATUS "IS_RHEL_X64_BUILD: ${IS_RHEL_X64_BUILD}")
ENDIF()
CHECK_BINARY_EXIST("libs/runtimes/rhel-x64/native" "*.so" HAVE_RHEL_X64 ${IS_RHEL_X64_BUILD})

#SET(IS_UBUNTU_ARM64_BUILD OFF)
#IF (("${TARGET_ARCH_NAME}" STREQUAL "ubuntu_arm64"))
#  SET(IS_UBUNTU_ARM64_BUILD ON)
#  MESSAGE(STATUS "IS_UBUNTU_ARM64_BUILD: ${IS_UBUNTU_ARM64_BUILD}")
#ENDIF()
#CHECK_BINARY_EXIST("libs/arm64" "*.so" HAVE_LINUX_ARM64 ${IS_UBUNTU_ARM64_BUILD})

IF ( IS_UBUNTU )
  #MESSAGE(STATUS "TARGET_ARCH_64: ${TARGET_ARCH_64}")
  #SET(NUGET_NATIVE_PLATFORM_ID_UBUNTU "${LSB_RELEASE_ID_SHORT}.${LSB_RELEASE_RELEASE_SHORT}-${NUGET_NATIVE_PLATFORM_ID_ARCH}")
  IF (NOT ("" STREQUAL "${LSB_RELEASE_ID_SHORT}"))
    SET(NUGET_NATIVE_PLATFORM_ID_UBUNTU "${LSB_RELEASE_ID_SHORT}-${NUGET_NATIVE_PLATFORM_ID_ARCH}")
  ELSEIF (NOT ("" STREQUAL "${DISTRO_ID}"))  
    SET(NUGET_NATIVE_PLATFORM_ID_UBUNTU "${DISTRO_ID}-${NUGET_NATIVE_PLATFORM_ID_ARCH}")
  ENDIF()
  MESSAGE(STATUS "NUGET_NATIVE_PLATFORM_ID_UBUNTU: ${NUGET_NATIVE_PLATFORM_ID_UBUNTU}")
ELSE()
  SET(UBUNTU_DEFAULT_PLATFORM_ID "ubuntu")
  IF (HAVE_UBUNTU_X86)
    SET(NUGET_NATIVE_PLATFORM_ID_UBUNTU "${UBUNTU_DEFAULT_PLATFORM_ID}-x86")
  ENDIF()
  IF (HAVE_UBUNTU_X64)
    SET(NUGET_NATIVE_PLATFORM_ID_UBUNTU "${UBUNTU_DEFAULT_PLATFORM_ID}-x64")
  ENDIF()
  IF (HAVE_UBUNTU_ARM64)
    SET(NUGET_NATIVE_PLATFORM_ID_UBUNTU "${UBUNTU_DEFAULT_PLATFORM_ID}-arm64")
  ENDIF()
ENDIF()
STRING(TOLOWER "${NUGET_NATIVE_PLATFORM_ID_UBUNTU}" NUGET_NATIVE_PLATFORM_ID_UBUNTU)

IF (IS_RHEL)
  SET(NUGET_NATIVE_PLATFORM_ID_RHEL "${DISTRO_ID}-${NUGET_NATIVE_PLATFORM_ID_ARCH}")
  MESSAGE(STATUS "NUGET_NATIVE_PLATFORM_ID_RHEL: ${NUGET_NATIVE_PLATFORM_ID_RHEL}")
ELSE()
  SET(RHEL_DEFAULT_PLATFORM_ID "rhel")
  IF (HAVE_RHEL_X86)
    SET(NUGET_NATIVE_PLATFORM_ID_RHEL "${RHEL_DEFAULT_PLATFORM_ID}-x86")
  ENDIF()
  IF (HAVE_RHEL_X64)
    SET(NUGET_NATIVE_PLATFORM_ID_RHEL "${RHEL_DEFAULT_PLATFORM_ID}-x64")
  ENDIF()
  IF (HAVE_RHEL_ARM64)
    SET(NUGET_NATIVE_PLATFORM_ID_RHEL "${RHEL_DEFAULT_PLATFORM_ID}-arm64")
  ENDIF()
ENDIF()
STRING(TOLOWER "${NUGET_NATIVE_PLATFORM_ID_RHEL}" NUGET_NATIVE_PLATFORM_ID_RHEL)


SET(HAVE_MAUI OFF)
IF(HAVE_IOS OR HAVE_MAC_CATALYST OR HAVE_ANDROID OR HAVE_WINDESKTOP)
  SET (HAVE_MAUI ON)
  MESSAGE(STATUS "HAVE_MAUI: ${HAVE_MAUI}")
ENDIF()

#IF (HAVE_MAUI)
SET(EMGUCV_MAUI_DOTNET_VERSION "net${DOTNET_VERSION_MAJOR}.0")

SET(EMGUCV_MAUI_ANDROID_SRC_FOLDER "${EMGUCV_MAUI_DOTNET_VERSION}-android")
SET(EMGUCV_MAUI_IOS_SRC_FOLDER "${EMGUCV_MAUI_DOTNET_VERSION}-ios")
SET(EMGUCV_MAUI_MACOS_SRC_FOLDER "${EMGUCV_MAUI_DOTNET_VERSION}-maccatalyst")
SET(EMGUCV_MAUI_WINDOWS_SRC_FOLDER "${EMGUCV_MAUI_DOTNET_VERSION}-windows10.0.19041.0")

SET(EMGUCV_MAUI_ANDROID_DST_FOLDER "${EMGUCV_MAUI_DOTNET_VERSION}-android33.0")
SET(EMGUCV_MAUI_IOS_DST_FOLDER "${EMGUCV_MAUI_DOTNET_VERSION}-ios16.1")
SET(EMGUCV_MAUI_MACOS_DST_FOLDER "${EMGUCV_MAUI_DOTNET_VERSION}-maccatalyst16.1")
SET(EMGUCV_MAUI_WINDOWS_DST_FOLDER "${EMGUCV_MAUI_DOTNET_VERSION}-windows10.0.19041.0")
#ENDIF()

  SET(WINDESKTOP_LABEL "")
  IF(HAVE_WINDESKTOP_X86)
    SET(WINDESKTOP_LABEL "${WINDESKTOP_LABEL}_x86")
  ENDIF()
  IF(HAVE_WINDESKTOP_X64)	
    SET(WINDESKTOP_LABEL "${WINDESKTOP_LABEL}_x64")
  ENDIF()
  IF(HAVE_WINDESKTOP_ARM64)	
    SET(WINDESKTOP_LABEL "${WINDESKTOP_LABEL}_arm64")
  ENDIF()
  
  IF("${WINDESKTOP_LABEL}" STREQUAL "_x86_x64_arm64")
    SET(WINDESKTOP_LABEL "-windesktop")
  ELSEIF(NOT ("${WINDESKTOP_LABEL}" STREQUAL ""))
    SET(WINDESKTOP_LABEL "-windesktop${WINDESKTOP_LABEL}")
  ENDIF()
  
  SET(WINSTORE_10_LABEL "")
  IF(HAVE_WINSTORE_10_X86)
    SET(WINSTORE_10_LABEL "${WINSTORE_10_LABEL}_x86")
  ENDIF()
  IF(HAVE_WINSTORE_10_X64)
    SET(WINSTORE_10_LABEL "${WINSTORE_10_LABEL}_x64")
  ENDIF()
  IF(HAVE_WINSTORE_10_ARM)	
    SET(WINSTORE_10_LABEL "${WINSTORE_10_LABEL}_arm")
  ENDIF()
  IF(HAVE_WINSTORE_10_ARM64)	
    SET(WINSTORE_10_LABEL "${WINSTORE_10_LABEL}_arm64")
  ENDIF()
  
  SET(HAVE_WINSTORE_10 OFF)
  IF(HAVE_WINSTORE_10_X86 OR HAVE_WINSTORE_10_X64 OR HAVE_WINSTORE_10_ARM OR HAVE_WINSTORE_10_ARM64)
    SET(HAVE_WINSTORE_10 ON)
  ENDIF()
  
  IF("${WINSTORE_10_LABEL}" STREQUAL "_x86_x64_arm64")
    SET(WINSTORE_10_LABEL "-UWP")
  ELSEIF(NOT ("${WINSTORE_10_LABEL}" STREQUAL ""))
    SET(WINSTORE_10_LABEL "-UWP${WINSTORE_10_LABEL}")
  ENDIF()
  
  SET(WINDOWS_LABEL "${WINSTORE_10_LABEL}${WINDESKTOP_LABEL}")
  IF ("${WINDOWS_LABEL}" STREQUAL "-UWP-windesktop")
    SET(WINDOWS_LABEL "-windows")
  ENDIF()
  
  SET(IOS_LABEL "")
  IF(HAVE_IOS)
    SET(IOS_LABEL "-ios")
  ENDIF()
  
  SET(MACOS_LABEL "")
  IF(HAVE_MACOS)
    SET(MACOS_LABEL "-macos")
  ENDIF()

IF (IS_DEBIAN_ARM_BUILD OR IS_DEBIAN_ARM64_BUILD OR IS_UBUNTU_X64_BUILD OR IS_UBUNTU_X86_BUILD OR IS_UBUNTU_ARM64_BUILD OR HAVE_LINUX_ARM OR HAVE_LINUX_ARM64 OR HAVE_LINUX_X64 OR HAVE_LINUX_X86 OR IS_RHEL_X64_BUILD OR HAVE_RHEL_X64)
  SET(HAVE_LINUX ON)
ELSE()
  SET(HAVE_LINUX OFF)
ENDIF()

SET(ANDROID_LABEL "")
IF(HAVE_ANDROID_ARM64_V8A)
  SET(ANDROID_LABEL "${ANDROID_LABEL}-arm64-v8a")
ENDIF()
#IF(HAVE_ANDROID_ARMEABI)
#  SET(ANDROID_LABEL "${ANDROID_LABEL}-armeabi")
#ENDIF()
IF(HAVE_ANDROID_ARMEABI_V7A)	
  SET(ANDROID_LABEL "${ANDROID_LABEL}-armeabi-v7a")
ENDIF()
IF(HAVE_ANDROID_X86)
  SET(ANDROID_LABEL "${ANDROID_LABEL}-x86")
ENDIF()
IF(HAVE_ANDROID_X86_64)
  SET(ANDROID_LABEL "${ANDROID_LABEL}-x86_64")
ENDIF()

#IF("${ANDROID_LABEL}" STREQUAL "-arm64-v8a-armeabi-armeabi-v7a-x86-x86_64")
IF("${ANDROID_LABEL}" STREQUAL "-arm64-v8a-armeabi-v7a-x86-x86_64")
  SET(ANDROID_LABEL "-android")
ELSEIF(NOT ("${ANDROID_LABEL}" STREQUAL ""))
  SET(ANDROID_LABEL "-android${ANDROID_LABEL}")
ENDIF()

#CHECK_BINARY_EXIST("libs" "Emgu.CV.World*" HAVE_PREBUILD_EMGU_CV_WORLD OFF)
#CHECK_BINARY_EXIST("libs" "Emgu.CV.Platform.IOS.*" HAVE_PREBUILD_EMGU_CV_IOS OFF)
#IF(HAVE_PREBUILD_EMGU_CV_IOS)
#  INSTALL(
#	FILES
#	"${CMAKE_SOURCE_DIR}/libs/Emgu.CV.Platform.IOS.dll"
#	"${CMAKE_SOURCE_DIR}/libs/Emgu.CV.Platform.IOS.xml"
#	DESTINATION "libs/"
#	COMPONENT emgucv_binary
#	)
#ENDIF()

IF (HAVE_IOS AND (NOT HAVE_MACOS) AND (NOT HAVE_ANDROID) AND (NOT HAVE_WINSTORE_10) AND (NOT (HAVE_WINDESKTOP_X86 OR HAVE_WINDESKTOP_X64 OR HAVE_WINDESKTOP_ARM64)) AND (NOT HAVE_LINUX))
  SET(HAVE_IOS_ONLY ON)
ELSE()
  SET(HAVE_IOS_ONLY OFF)
ENDIF()

# ----------------------------------------------------------------------------
#  Setup Package information
# ----------------------------------------------------------------------------
SET(PACKAGE "${PROJECT_NAME}")
SET(GITHUB_REPO_URL "https://github.com/emgucv/emgucv")
SET(CPACK_PACKAGE_CONTACT "Emgu CV SUPPORT <support@emgu.com>")
SET(PACKAGE_BUGREPORT "${CPACK_PACKAGE_CONTACT}")
SET(PACKAGE_NAME "${PROJECT_NAME}")

#SET(CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Emgu CV is a cross platform .Net wrapper to the OpenCV image processing library.")

SET(CPACK_PACKAGE_NAME "${PACKAGE_NAME}${IOS_LABEL}${ANDROID_LABEL}${MACOS_LABEL}${WINDOWS_LABEL}")

#STRING(LENGTH "${CPACK_PACKAGE_NAME}" PACKAGE_NAME_LENGTH)
#IF (${PACKAGE_NAME_LENGTH} GREATER 30)
#   SET(CPACK_PACKAGE_NAME "${PACKAGE_NAME}-mixed")
#   STRING(LENGTH "${CPACK_PACKAGE_NAME}" PACKAGE_NAME_LENGTH)
#ENDIF()

#IF (APPLE)
#  SET(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-macos")
#ENDIF()

IF(WITH_CUDA)
  SET(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-cuda")
ENDIF()

IF(WITH_OPENNI) 
  SET(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-openni")
ENDIF()

IF(CV_ICC)
  SET(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-icc")
ENDIF()

#IF(WITH_TBB)
#  SET(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-tbb")
#ENDIF()

IF(WITH_IPP)
  SET(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-ipp")
ENDIF()

IF(WITH_INF_ENGINE OR WITH_OPENVINO)
  SET(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-dldt")
ENDIF()

SET(IS_PRO_BUILD FALSE)
IF("${CPACK_PACKAGE_NAME}" STREQUAL "${PACKAGE_NAME}-ios-android-macos-windows-ipp-dldt")
  SET(CPACK_PACKAGE_NAME "${PACKAGE_NAME}-pro")
  SET(IS_PRO_BUILD TRUE)
ENDIF()


#IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Commercial.License.txt")
#  SET(LICENSE_FILE_NAME "Emgu.CV.Commercial.License.txt")
#ELSE()
SET(LICENSE_FILE_NAME "LICENSE")

SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/${LICENSE_FILE_NAME}")

#IF (WIN32 OR APPLE OR ANDROID)
SET(CPACK_PACKAGE_CLI_FOLDER libs)
#ELSE ()
#  SET(CPACK_PACKAGE_CLI_FOLDER lib/cli/${PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR})
#ENDIF()

# ----------------------------------------------------------------------------
#  Build opencv and Emgu.CV.Extern
# ----------------------------------------------------------------------------
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${UNMANAGED_LIBRARY_OUTPUT_PATH}" )
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")

#SET(CMAKE_ARCHIEVE_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
#SET(CMAKE_ARCHIEVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_ARCHIEVE_OUTPUT_DIRECTORY}")
#SET(CMAKE_ARCHIEVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_ARCHIEVE_OUTPUT_DIRECTORY}")

#SET(CMAKE_INSTALL_PREFIX_COPY ${CMAKE_INSTALL_PREFIX})
#SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}${UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER})
#SET(CPACK_PACKAGING_INSTALL_PREFIX ${UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER})
#SET(DESTDIR ${UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER})
#SET(CPACK_OUTPUT_FILE_PREFIX "x64")

SET(ENTRYPOINT_CS_STRING "")
SET(ENTRYPOINT_MODULES_STRING "")

#Add opencl
#IF(WIN32 AND (NOT NETFX_CORE) )
#  IF(WITH_OPENCL)
#    MESSAGE(STATUS "Open CL build included")
#	SET(OPENCL_SOURCE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/lib/opencl-icd-1.2.11.0/icd")
#	ADD_SUBDIRECTORY(${OPENCL_SOURCE_FOLDER})
#	#GET_TARGET_PROPERTY(OPENCL_OUTPUT_NAME OpenCL OUTPUT_NAME)

#	set(OPENCL_FOUND YES)
#	set(OPENCL_LIBRARY "${CMAKE_CURRENT_SOURCE_DIR}/bin/Release/opencl.lib" CACHE STRING "OpenCL library")
#	set(OPENCL_INCLUDE_DIR "${OPENCL_SOURCE_FOLDER}/inc" CACHE STRING "OpenCL include directory")
#	mark_as_advanced(OPENCL_INCLUDE_DIR OPENCL_LIBRARY)

#	SET(ENTRYPOINT_MODULES_STRING "${ENTRYPOINT_MODULES_STRING}
#	     OpenclLibrary,")
#   SET(ENTRYPOINT_CS_STRING "${ENTRYPOINT_CS_STRING} 
#      /// <summary>
#      /// The file name of the OpenCL library
#      /// </summary>
#      public const string OpenclLibrary = \"OpenCL\";")
#  ELSE()
#    SET(OPENCL_OUTPUT_NAME "")
#	MESSAGE(STATUS "Open CL build not included")
#  ENDIF()
#ENDIF()

SET(CMAKE_OLD_SOURCE_DIR ${CMAKE_SOURCE_DIR})
SET(CMAKE_SOURCE_DIR ${OPENCV_SUBFOLDER})
IF(MSVC)
  set(ENABLE_SOLUTION_FOLDERS ON CACHE BOOL "Solution folder in Visual Studio")
ENDIF()
ADD_SUBDIRECTORY(${OPENCV_SUBFOLDER})

SET(CMAKE_SOURCE_DIR ${CMAKE_OLD_SOURCE_DIR})

SET (OPENCV_MODULE_NAME_CANDIDATES
  core imgproc video flann ml imgcodecs videoio highgui objdetect features2d calib3d
  cudaarithm cudawarping cudafilters cudaimgproc cudalegacy cudaoptflow 
  cudastereo cudabgsegm cudafeatures2d cudacodec cudaobjdetect
  photo superres  
  videostab shape
  cudev  
  face ximgproc xobjdetect xfeatures2d xphoto bgsegm optflow
  stitching plot
  dnn dnn_objdetect dnn_superres aruco fuzzy viz bioinspired text tracking
  dpm
  saliency
  img_hash
  phase_unwrapping
  freetype
  hfs
  quality
  stereo
  surface_matching
  alphamat
  intensity_transform
  rapid
  line_descriptor
  mcc
  hdf
  gapi
  wechat_qrcode
  structured_light
  rgbd
  reg
  )
  
IF(BUILD_opencv_world)
  LIST (APPEND OPENCV_MODULE_NAME_CANDIDATES world)
ENDIF()

FOREACH(OPENCV_MODULE_NAME ${OPENCV_MODULE_NAME_CANDIDATES})
  IF(TARGET opencv_${OPENCV_MODULE_NAME})
    LIST(APPEND OPENCV_MODULE_NAMES ${OPENCV_MODULE_NAME})  
  ENDIF() 
ENDFOREACH()

# ----------------------------------------------------------------------------
#  Autodetect if we are in a GIT repository
# ----------------------------------------------------------------------------

IF(GIT_EXECUTABLE)
  MESSAGE(STATUS "Extracting Emgu CV git version, please wait...")
  EXECUTE_PROCESS(
    WORKING_DIRECTORY  ${CMAKE_CURRENT_SOURCE_DIR}
    COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
    OUTPUT_VARIABLE GITVERSION_RESULT)
  STRING(REGEX REPLACE "^([0123456789]+).*" "\\1" EMGUCV_GITVERSION "${GITVERSION_RESULT}")
  STRING(STRIP "${EMGUCV_GITVERSION}" EMGUCV_GITVERSION)
  IF(EMGUCV_GITVERSION MATCHES "^$" OR EMGUCV_GITVERSION MATCHES "^-")
    # This is NOT a git repository:
    SET(EMGUCV_GITVERSION "0")
  ENDIF()
  MESSAGE(STATUS "Emgu CV GIT VERSION: ${EMGUCV_GITVERSION}")
ELSE()
  # We don't have git:
  SET(EMGUCV_GITVERSION "0")
ENDIF()


SET(CPACK_PACKAGE_VENDOR "Emgu Corporation")
SET(CPACK_PACKAGE_VERSION_MAJOR ${OPENCV_VERSION_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${OPENCV_VERSION_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${OPENCV_VERSION_PATCH})
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${EMGUCV_GITVERSION}")
IF(ANDROID)
  SET(CPACK_PACKAGE_FILE_NAME "lib${CPACK_PACKAGE_NAME}")
ELSE()
  SET(CPACK_PACKAGE_FILE_NAME "lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
ENDIF()

MESSAGE(STATUS "Package name will be ${CPACK_PACKAGE_NAME}")
FILE(WRITE "emgucv.version.txt" "${CPACK_PACKAGE_VERSION}")

MATH(EXPR CPACK_PACKAGE_VERSION_PATCH_PLUS_ONE "${CPACK_PACKAGE_VERSION_PATCH}+1")
#SET(CPACK_PACKAGE_DEPENDENCY_VERSION "[${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.0,${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH_PLUS_ONE}.0)")
#SET(CPACK_PACKAGE_DEPENDENCY_VERSION "(${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.0, ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH_PLUS_ONE}.0)")
SET(CPACK_PACKAGE_DEPENDENCY_VERSION "${CPACK_PACKAGE_VERSION}")
SET(NUGET_PACKAGE_DEPENDENCY_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.*")

#IF(NETFX_CORE)
#  SET(EMGU_CV_WITH_TESSERACT OFF CACHE BOOL "BUILD TESSERACT OCR")
#ELSE()
SET(EMGU_CV_WITH_TESSERACT ON CACHE BOOL "BUILD TESSERACT OCR")
#ENDIF()

IF(MSVC AND WIN32 AND EMGUCV_WITH_TESSERACT)
  SET(TESSERACT_OPENCL OFF CACHE BOOL "ENABLE OpenCL for TESSERACT")
ELSE()
  SET(TESSERACT_OPENCL OFF CACHE BOOL "ENABLE OpenCL for TESSERACT")
ENDIF()

IF(TESSERACT_OPENCL)
  ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/3rdParty/opencl-icd-1.2.11.0/icd)
ENDIF()

IF (TARGET_ARCH_64)
  SET(EMGU_ENABLE_SSE OFF CACHE BOOL "ENABLE SSE for Emgu CV")
ELSE()
  SET(EMGU_ENABLE_SSE ON CACHE BOOL "ENABLE SSE for Emgu CV")
ENDIF()
ADD_SUBDIRECTORY(Emgu.CV.Extern)
ADD_SUBDIRECTORY(Emgu.CV.NativeImage)

IF(NOT (ANDROID OR IOS OR NETFX_CORE OR APPLE))
  ENABLE_TESTING()
  ADD_SUBDIRECTORY(tests/cvextern_test)
ENDIF()

SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}" )
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
#SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX_COPY})
#SET(CPACK_PACKAGING_INSTALL_PREFIX "")
#SET(DESTDIR "")
#SET(CPACK_OUTPUT_FILE_PREFIX "")

SET(EMGU_CV_BUILD ON CACHE BOOL "BUILD Emgu CV")
SET(EMGU_CV_EXAMPLE_BUILD ON CACHE BOOL "Build Emgu CV Example")

# ----------------------------------------------------------------------------
#  Generate required common assembly file for Emgu CV project
# ----------------------------------------------------------------------------
INCLUDE(Today)
TODAY() #set the variable CURRENT_YEAR

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonAssemblyInfo.cs.in ${CMAKE_CURRENT_SOURCE_DIR}/CommonAssemblyInfo.cs)

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Directory.Build.props)

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Extern/version.rc)

SET (EMGUCV_LICENSE_FILE "${LICENSE_FILE_NAME}.txt")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${LICENSE_FILE_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/${EMGUCV_LICENSE_FILE} COPYONLY)

MACRO(CHECK_LICENSE_TYPE)
	MESSAGE(STATUS "LICENSE FILE: ${CMAKE_CURRENT_SOURCE_DIR}/${LICENSE_FILE_NAME}")
    IF (WIN32)
        EXECUTE_PROCESS(COMMAND "findstr" "gpl" "${LICENSE_FILE_NAME}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE TMP)
	ELSE()	
	    EXECUTE_PROCESS(COMMAND "grep" "gpl" "${LICENSE_FILE_NAME}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE TMP)
	ENDIF()
	
	STRING(STRIP "${TMP}" TMP)
	STRING(LENGTH "${TMP}" GPL_LICENSE_LENGTH)
	SET (LICENSE_TYPE "Dual License")
	
	IF(${GPL_LICENSE_LENGTH} EQUAL 0)
		SET(LICENSE_TYPE "Commercial")		
	ENDIF()
	
	MESSAGE(STATUS "LICENSE_TYPE: ${LICENSE_TYPE}")
ENDMACRO()
CHECK_LICENSE_TYPE()

# ----------------------------------------------------------------------------
#  Generate neget packaging file for Emgu CV project
# ----------------------------------------------------------------------------

IF( "${OPENCV_EXTRA_MODULES_PATH}" STREQUAL "" )
  SET(EMGUCV_RUNTIME_EXTRA_TAG ".mini")
  SET(EMGUCV_MINI_RELEASE_NOTE "This is the mini release that only contains the minimum amount of Open CV modules. For full release that contains all Open CV modules, use a release that is not labeled 'mini'.")
ELSE()
  SET(EMGUCV_RUNTIME_EXTRA_TAG "")
  SET(EMGUCV_MINI_RELEASE_NOTE "")
ENDIF()

SET(EMGUCV_NUGET_ID "Emgu.CV")
SET(EMGUCV_BITMAP_NUGET_ID "Emgu.CV.Bitmap")
SET(EMGUCV_WPF_NUGET_ID "Emgu.CV.Wpf")
SET(EMGUCV_MODELS_NUGET_ID "Emgu.CV.Models")
SET(EMGUCV_UI_NUGET_ID "Emgu.CV.UI")
SET(EMGUCV_WINDOWS_NUGET_ID "${EMGUCV_NUGET_ID}.runtime${EMGUCV_RUNTIME_EXTRA_TAG}.windows")
SET(EMGU_WINDOWS_MSVCRT_X86_NUGET_ID "Emgu.runtime.windows.msvc.rt.x86")
SET(EMGU_WINDOWS_MSVCRT_X64_NUGET_ID "Emgu.runtime.windows.msvc.rt.x64")
SET(EMGU_WINDOWS_MSVCRT_ARM64_NUGET_ID "Emgu.runtime.windows.msvc.rt.arm64")
SET(EMGU_ZLIBWAPI_ID "Emgu.runtime.windows.zlibwapi.x64")
SET(EMGU_ZLIBWAPI_VERSION "1.2.3")

SET(NUGET_EMGU_URL "https://www.emgu.com")

IF(WITH_CUDA)
	SET(EMGUCV_WINDOWS_NUGET_ID "${EMGUCV_WINDOWS_NUGET_ID}.cuda")
	SET(EMGU_WINDOWS_CUDA_NUGET_ID "Emgu.runtime.windows.cuda")
	SET(EMGU_CUDART_NUGET_ID "${EMGU_WINDOWS_CUDA_NUGET_ID}.rt")
	SET(EMGU_CUDA_BLAS_NUGET_ID "${EMGU_WINDOWS_CUDA_NUGET_ID}.blas")
	SET(EMGU_CUDA_BLAS_LT_NUGET_ID "${EMGU_CUDA_BLAS_NUGET_ID}.lt")
	SET(EMGU_NPP_NUGET_ID "${EMGU_WINDOWS_CUDA_NUGET_ID}.npp")
	SET(EMGU_CUFFT_NUGET_ID "${EMGU_WINDOWS_CUDA_NUGET_ID}.fft")
	SET(EMGU_CUDNN_NUGET_ID "${EMGU_WINDOWS_CUDA_NUGET_ID}.dnn")
	SET(EMGU_CUDNN_ADV_NUGET_ID "${EMGU_CUDNN_NUGET_ID}.adv")
	SET(EMGU_CUDNN_CNN_NUGET_ID "${EMGU_CUDNN_NUGET_ID}.cnn")
	SET(EMGU_CUDNN_ENGINES_NUGET_ID "${EMGU_CUDNN_NUGET_ID}.engines")
	SET(EMGU_CUDNN_OPS_NUGET_ID "${EMGU_CUDNN_NUGET_ID}.ops")
#ELSE()
#	SET(EMGUCV_NUGET_ID "${EMGUCV_NUGET_ID_BASE}")
ENDIF()

IF(HAVE_MACOS)
  SET(EMGUCV_MACOS_NUGET_ID "${EMGUCV_NUGET_ID}.runtime${EMGUCV_RUNTIME_EXTRA_TAG}.macos")
ENDIF()

IF(HAVE_ANDROID)
  SET(EMGUCV_MAUI_ANDROID_NUGET_ID "${EMGUCV_NUGET_ID}.runtime.maui${EMGUCV_RUNTIME_EXTRA_TAG}.android")
ENDIF()

IF(HAVE_IOS)
  SET(EMGUCV_MAUI_IOS_NUGET_ID "${EMGUCV_NUGET_ID}.runtime.maui${EMGUCV_RUNTIME_EXTRA_TAG}.ios")
ENDIF()

IF(HAVE_MAC_CATALYST)
  SET(EMGUCV_MAUI_MACOS_NUGET_ID "${EMGUCV_NUGET_ID}.runtime.maui${EMGUCV_RUNTIME_EXTRA_TAG}.macos")
ENDIF()

IF(HAVE_WINSTORE_10 AND WIN32)
  SET(EMGUCV_UWP_NUGET_ID "${EMGUCV_NUGET_ID}.runtime${EMGUCV_RUNTIME_EXTRA_TAG}.uwp")
ENDIF()

IF(HAVE_LINUX_ARM)
  SET(EMGUCV_DEBIAN_ARM_NUGET_ID "${EMGUCV_NUGET_ID}.runtime${EMGUCV_RUNTIME_EXTRA_TAG}.debian-arm")
ENDIF()

IF(HAVE_LINUX_ARM64)
  SET(EMGUCV_DEBIAN_ARM64_NUGET_ID "${EMGUCV_NUGET_ID}.runtime${EMGUCV_RUNTIME_EXTRA_TAG}.debian-arm64")
ENDIF()

IF(HAVE_UBUNTU_X64 OR HAVE_UBUNTU_X86 OR HAVE_UBUNTU_ARM64)
  SET(EMGUCV_UBUNTU_NUGET_ID "${EMGUCV_NUGET_ID}.runtime${EMGUCV_RUNTIME_EXTRA_TAG}.${NUGET_NATIVE_PLATFORM_ID_UBUNTU}")
ENDIF()

IF(HAVE_RHEL_X64 OR HAVE_RHEL_X86)
  SET(EMGUCV_RHEL_NUGET_ID "${EMGUCV_NUGET_ID}.runtime${EMGUCV_RUNTIME_EXTRA_TAG}.${NUGET_NATIVE_PLATFORM_ID_RHEL}")
ENDIF()

IF ("${LICENSE_TYPE}" STREQUAL "Commercial")
	MESSAGE(STATUS "Configuring nuget package for commercial only release")
ELSEIF()
	MESSAGE(STATUS "Configuring nuget package for dual license release")
ENDIF()

IF(WITH_OPENVINO OR WITH_INF_ENGINE)
  SET(EMGUCV_WINDOWS_NUGET_ID "${EMGUCV_WINDOWS_NUGET_ID}.dldt")
ENDIF()

SET(EMGUCV_MACOS_NUGET_FILE_LIST "")
IF(HAVE_MACOS)
  SET(EMGUCV_MACOS_NUGET_FILE_LIST "${EMGUCV_MACOS_NUGET_FILE_LIST} 
  <file src=\"..\\..\\..\\libs\\runtimes\\osx\\native\\*.dylib\" target=\"runtimes\\osx\\native\"/>
  <file src=\"..\\..\\..\\libs\\runtimes\\osx\\native\\*.inc\" target=\"docs\\\" />
  <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
  <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />
  <file src=\"docs\\README.md\" target=\"docs\\\" />
  <file src=\"Emgu.CV.runtime.macos.props\" target=\"build\\\" />")
ENDIF()

SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "")
IF(HAVE_WINDESKTOP_X86)
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win-x86\\native\\*.dll\" exclude=\"..\\..\\..\\libs\\runtimes\\win-x86\\native\\cu*.dll;..\\..\\..\\libs\\runtimes\\win-x86\\native\\npp*.dll;..\\..\\..\\libs\\runtimes\\win-x86\\native\\concrt*.dll;..\\..\\..\\libs\\runtimes\\win-x86\\native\\msvcp*.dll;..\\..\\..\\libs\\runtimes\\win-x86\\native\\vcruntime*.dll;..\\..\\..\\libs\\runtimes\\win-x86\\native\\vccorlib*.dll\" target=\"runtimes\\win-x86\\native\" />")
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win-x86\\native\\version_string.inc\" target=\"docs\\build_info_x86.inc\" />")
	SET(EMGU_WINDOWS_MSVCRT_X86_NUGET_TITLE "MSVC x86 runtime for windows")
	SET(EMGU_WINDOWS_MSVCRT_X86_NUGET_FILE_LIST "${EMGU_WINDOWS_MSVCRT_X86_NUGET_FILE_LIST} 
	<file src=\"..\\..\\..\\libs\\runtimes\\win-x86\\native\\concrt*.dll\" target=\"runtimes\\win-x86\\native\" /> 
	<file src=\"..\\..\\..\\libs\\runtimes\\win-x86\\native\\msvcp*.dll\" target=\"runtimes\\win-x86\\native\" /> 
	<file src=\"..\\..\\..\\libs\\runtimes\\win-x86\\native\\vcruntime*.dll\" target=\"runtimes\\win-x86\\native\" />     
	<file src=\"..\\..\\..\\libs\\runtimes\\win-x86\\native\\vccorlib*.dll\" target=\"runtimes\\win-x86\\native\" />     
	<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />")
	INSTALL(
      FILES
      "libs/runtimes/win-x86/native/version_string.inc"
      DESTINATION "libs/runtimes/win-x86/native/"
      COMPONENT emgucv_binary
      )
ENDIF()
IF(HAVE_WINDESKTOP_X64)
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\*.dll\" exclude=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cu*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\npp*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\concrt*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\msvcp*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\vcruntime*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\vccorlib*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\zlibwapi.dll\" target=\"runtimes\\win-x64\\native\" />")
	#Also added configuration files from OpenVino
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\*.xml\" target=\"runtimes\\win-x64\\native\" />")
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\*.json\" target=\"runtimes\\win-x64\\native\" />")
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\*.elf\" target=\"runtimes\\win-x64\\native\" />")
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\*.mvcmd\" target=\"runtimes\\win-x64\\native\" />")
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\version_string.inc\" target=\"docs\\build_info_x64.inc\" />")
	SET(EMGU_WINDOWS_MSVCRT_X64_NUGET_TITLE "MSVC x64 runtime for windows")
	SET(EMGU_WINDOWS_MSVCRT_X64_NUGET_FILE_LIST "${EMGU_WINDOWS_MSVCRT_X64_NUGET_FILE_LIST} 
	<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\concrt*.dll\" target=\"runtimes\\win-x64\\native\" /> 
	<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\msvcp*.dll\" target=\"runtimes\\win-x64\\native\" /> 
	<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\vcruntime*.dll\" target=\"runtimes\\win-x64\\native\" />     
	<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\vccorlib*.dll\" target=\"runtimes\\win-x64\\native\" />     
	<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />")
	
	SET(EMGU_WINDOWS_ZLIBWAPI_X64_NUGET_FILE_LIST "${EMGU_WINDOWS_ZLIBWAPI_X64_NUGET_FILE_LIST}
	<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\zlibwapi.dll\" target=\"runtimes\\win-x64\\native\" /> 
	<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
	<file src=\"zlib_license.txt\" target=\"\" />")
    INSTALL(
      FILES
      "libs/runtimes/win-x64/native/version_string.inc"
      DESTINATION "libs/runtimes/win-x64/native/"
      COMPONENT emgucv_binary
      )
ENDIF()
IF(HAVE_WINDESKTOP_ARM64)
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} 
	   <file src=\"..\\..\\..\\libs\\runtimes\\win-arm64\\native\\*.dll\" exclude=\"..\\..\\..\\libs\\runtimes\\win-arm64\\native\\cu*.dll;..\\..\\..\\libs\\runtimes\\win-arm64\\native\\npp*.dll;..\\..\\..\\libs\\runtimes\\win-arm64\\native\\concrt*.dll;..\\..\\..\\libs\\runtimes\\win-arm64\\native\\msvcp*.dll;..\\..\\..\\libs\\runtimes\\win-arm64\\native\\vcruntime*.dll;..\\..\\..\\libs\\runtimes\\win-arm64\\native\\vccorlib*.dll;..\\..\\..\\libs\\runtimes\\win-arm64\\native\\opencv_videoio_ffmpeg*.dll\" target=\"runtimes\\win-arm64\\native\" />
	   <file src=\"..\\..\\..\\libs\\runtimes\\win-arm64\\native\\version_string.inc\" target=\"docs\\build_info_arm64.inc\" />")
	SET(EMGU_WINDOWS_MSVCRT_ARM64_NUGET_TITLE "MSVC arm64 runtime for windows")
	SET(EMGU_WINDOWS_MSVCRT_ARM64_NUGET_FILE_LIST "${EMGU_WINDOWS_MSVCRT_ARM64_NUGET_FILE_LIST} 
	<file src=\"..\\..\\..\\libs\\runtimes\\win-arm64\\native\\concrt*.dll\" target=\"runtimes\\win-arm64\\native\" />
	<file src=\"..\\..\\..\\libs\\runtimes\\win-arm64\\native\\msvcp*.dll\" target=\"runtimes\\win-arm64\\native\" />
	<file src=\"..\\..\\..\\libs\\runtimes\\win-arm64\\native\\vcruntime*.dll\" target=\"runtimes\\win-arm64\\native\" />
	<file src=\"..\\..\\..\\libs\\runtimes\\win-arm64\\native\\vccorlib*.dll\" target=\"runtimes\\win-arm64\\native\" />
	<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />")
	INSTALL(
      FILES
      "libs/runtimes/win-arm64/native/version_string.inc"
      DESTINATION "libs/runtimes/win-arm64/native/"
      COMPONENT emgucv_binary
      )
ENDIF()
IF(HAVE_WINDESKTOP_X86 OR HAVE_WINDESKTOP_X64 OR HAVE_WINDESKTOP_ARM64)
	SET(EMGUCV_WINDOWS_NUGET_FILE_LIST "${EMGUCV_WINDOWS_NUGET_FILE_LIST} 
    <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />
	<file src=\"README.md\" target=\"docs\\\" />")
ENDIF()

SET(EMGUCV_MAUI_MACOS_NUGET_FILE_LIST "")

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.macos.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/Mac/Directory.Build.props)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.macos.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/Mac/docs/README.md)

SET(EMGUCV_UWP_NUGET_FILE_LIST "")
IF(HAVE_WINSTORE_10_X86)
	SET(EMGUCV_UWP_NUGET_FILE_LIST "${EMGUCV_UWP_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win10-x86\\native\\*.dll\" target=\"runtimes\\win10-x86\\native\" />")
ENDIF()
IF(HAVE_WINSTORE_10_X64)
	SET(EMGUCV_UWP_NUGET_FILE_LIST "${EMGUCV_UWP_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win10-x64\\native\\*.dll\" target=\"runtimes\\win10-x64\\native\" />")
ENDIF()
IF(HAVE_WINSTORE_10_ARM)
	SET(EMGUCV_UWP_NUGET_FILE_LIST "${EMGUCV_UWP_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win10-arm\\native\\*.dll\" target=\"runtimes\\win10-arm\\native\" />")
ENDIF()
IF(HAVE_WINSTORE_10_ARM64)
	SET(EMGUCV_UWP_NUGET_FILE_LIST "${EMGUCV_UWP_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\win10-arm64\\native\\*.dll\" target=\"runtimes\\win10-arm64\\native\" />")
ENDIF()
IF(HAVE_WINSTORE_10)
    SET(EMGUCV_UWP_NUGET_DEPENDENCY "
    <dependencies>
      <dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
    </dependencies>")
	#<file src=\"Emgu.CV.runtime.uwp.targets\" target=\"build\\${EMGUCV_UWP_NUGET_ID}.targets\" />
	SET(EMGUCV_UWP_NUGET_FILE_LIST "${EMGUCV_UWP_NUGET_FILE_LIST} 
    <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />")
ENDIF()

SET(EMGUCV_DEBIAN_ARM_NUGET_FILE_LIST "")
SET(EMGUCV_DEBIAN_ARM64_NUGET_FILE_LIST "")
SET(EMGUCV_DEBIAN_NUGET_DEPENDENCY "    <dependencies>
      <dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
      </dependencies>")
IF(HAVE_LINUX_ARM)
	SET(EMGUCV_DEBIAN_ARM_NUGET_FILE_LIST "${EMGUCV_DEBIAN_ARM_NUGET_FILE_LIST} 
      <file src=\"..\\..\\..\\libs\\runtimes\\linux-arm\\native\\*.so\" target=\"runtimes\\linux-arm\\native\" />")
	
	SET(EMGUCV_DEBIAN_ARM_NUGET_FILE_LIST "${EMGUCV_DEBIAN_ARM_NUGET_FILE_LIST} 
	  <file src=\"..\\..\\..\\libs\\runtimes\\linux-arm\\native\\debian_arm_version_string.inc\" target=\"docs\\build_info_arm.inc\" />")
	
	SET(EMGUCV_DEBIAN_ARM_NUGET_FILE_LIST "${EMGUCV_DEBIAN_ARM_NUGET_FILE_LIST} 
      <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
      <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />
	  <file src=\"Emgu.CV.runtime.debian-arm.props\" target=\"build\\\" />")
ENDIF()
IF(HAVE_LINUX_ARM64)
	SET(EMGUCV_DEBIAN_ARM64_NUGET_FILE_LIST "${EMGUCV_DEBIAN_ARM64_NUGET_FILE_LIST} 
      <file src=\"..\\..\\..\\libs\\runtimes\\linux-arm64\\native\\*.so\" target=\"runtimes\\linux-arm64\\native\" />")
	  
	SET(EMGUCV_DEBIAN_ARM64_NUGET_FILE_LIST "${EMGUCV_DEBIAN_ARM64_NUGET_FILE_LIST} 
	  <file src=\"..\\..\\..\\libs\\runtimes\\linux-arm64\\native\\debian_arm64_version_string.inc\" target=\"docs\\build_info_arm64.inc\" />")  
	  
	SET(EMGUCV_DEBIAN_ARM64_NUGET_FILE_LIST "${EMGUCV_DEBIAN_ARM64_NUGET_FILE_LIST} 
      <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
      <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />
	  <file src=\"Emgu.CV.runtime.debian-arm64.props\" target=\"build\\\" />")
ENDIF()

SET(EMGUCV_UBUNTU_NUGET_FILE_LIST "")
IF(HAVE_UBUNTU_X64)
  SET(EMGUCV_UBUNTU_NUGET_FILE_LIST "${EMGUCV_UBUNTU_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\ubuntu-x64\\native\\*.so\" target=\"runtimes\\ubuntu-x64\\native\" />")
ENDIF()
IF(HAVE_UBUNTU_X86)
  SET(EMGUCV_UBUNTU_NUGET_FILE_LIST "${EMGUCV_UBUNTU_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\ubuntu-x86\\native\\*.so\" target=\"runtimes\\ubuntu-x86\\native\" />")
ENDIF()
IF(HAVE_UBUNTU_ARM64)
  SET(EMGUCV_UBUNTU_NUGET_FILE_LIST "${EMGUCV_UBUNTU_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\ubuntu-arm64\\native\\*.so\" target=\"runtimes\\ubuntu-arm64\\native\" />")
ENDIF()
IF(HAVE_UBUNTU_X64 OR HAVE_UBUNTU_X86 OR HAVE_UBUNTU_ARM64)
    SET(EMGUCV_UBUNTU_NUGET_DEPENDENCY "
    <dependencies>
      <dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
    </dependencies>")
	SET(EMGUCV_UBUNTU_NUGET_FILE_LIST "${EMGUCV_UBUNTU_NUGET_FILE_LIST} 
    <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />	
    <file src=\"README.md\" target=\"docs\\\" />
	<file src=\"Emgu.CV.runtime.ubuntu.props\" target=\"build\\\" />")
	IF(HAVE_UBUNTU_X86)
	  SET(EMGUCV_UBUNTU_NUGET_FILE_LIST "${EMGUCV_UBUNTU_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\ubuntu-x86\\native\\ubuntu_x86_version_string.inc\" target=\"docs\\build_info_x86.inc\" /> ")
	ENDIF()
	IF(HAVE_UBUNTU_X64)
	  SET(EMGUCV_UBUNTU_NUGET_FILE_LIST "${EMGUCV_UBUNTU_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\ubuntu-x64\\native\\ubuntu_x64_version_string.inc\" target=\"docs\\build_info_x64.inc\" /> ")
	ENDIF()
	IF(HAVE_UBUNTU_ARM64)
	  SET(EMGUCV_UBUNTU_NUGET_FILE_LIST "${EMGUCV_UBUNTU_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\ubuntu-arm64\\native\\ubuntu_arm64_version_string.inc\" target=\"docs\\build_info_arm64.inc\" /> ")
	ENDIF()
ENDIF()

SET(EMGUCV_RHEL_NUGET_FILE_LIST "")
IF(HAVE_RHEL_X64)
  SET(EMGUCV_RHEL_NUGET_FILE_LIST "${EMGUCV_RHEL_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\rhel-x64\\native\\*.so\" target=\"runtimes\\rhel-x64\\native\" />")
ENDIF()
IF(HAVE_RHEL_X86)
  SET(EMGUCV_RHEL_NUGET_FILE_LIST "${EMGUCV_RHEL_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\rhel-x86\\native\\*.so\" target=\"runtimes\\rhel-x86\\native\" />")
ENDIF()
IF(HAVE_RHEL_ARM64)
  SET(EMGUCV_RHEL_NUGET_FILE_LIST "${EMGUCV_RHEL_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\rhel-arm64\\native\\*.so\" target=\"runtimes\\rhel-arm64\\native\" />")
ENDIF()
IF(HAVE_RHEL_X64 OR HAVE_RHEL_X86 OR HAVE_RHEL_ARM64)
    SET(EMGUCV_RHEL_NUGET_DEPENDENCY "
    <dependencies>
      <dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
    </dependencies>")
	SET(EMGUCV_RHEL_NUGET_FILE_LIST "${EMGUCV_RHEL_NUGET_FILE_LIST} 
    <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />
    <file src=\"README.md\" target=\"docs\\\" />
	<file src=\"Emgu.CV.runtime.rhel.props\" target=\"build\\\" />")
	IF(HAVE_RHEL_X64)
	  SET(EMGUCV_RHEL_NUGET_FILE_LIST "${EMGUCV_RHEL_NUGET_FILE_LIST} <file src=\"..\\..\\..\\libs\\runtimes\\rhel-x64\\native\\rhel_x64_version_string.inc\" target=\"docs\\build_info_x64.inc\" /> ")
	ENDIF()
ENDIF()


#SET(EMGUCV_NUGET_FILE_LIST "")
#SET(EMGUCV_NUGET_DEPENDENCY "")
SET(EMGUCV_NUGET_FRAMEWORK_REFERENCES "")



# find the System.Text.Json nuget pacakge version
SET(EMGUCV_PLATFORM_NETSTANDARD_PROJECT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV/NetStandard/Emgu.CV.csproj")
file(STRINGS "${EMGUCV_PLATFORM_NETSTANDARD_PROJECT_FILE}" EMGUCV_PLATFORM_NETSTANDARD_PROJECT_SYSTEM_TEXT_JSON REGEX "System.Text.Json" )
string(REGEX REPLACE ".+Version=\"([0-9]+.[0-9]+.[0-9]+)\".*" "\\1" SYSTEM_TEXT_JSON_VERSION "${EMGUCV_PLATFORM_NETSTANDARD_PROJECT_SYSTEM_TEXT_JSON}")
MESSAGE(STATUS "System.Text.Json = ${SYSTEM_TEXT_JSON_VERSION}")
# find the System.Drawing.Common nuget package version
SET(EMGUCV_MODELS_NETSTANDARD_PROJECT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Models/NetStandard/Emgu.CV.Models.csproj")
file(STRINGS "${EMGUCV_MODELS_NETSTANDARD_PROJECT_FILE}" EMGUCV_MODELS_NETSTANDARD_PROJECT_SYSTEM_DRAWING_COMMON REGEX "System.Drawing.Common" )
string(REGEX REPLACE ".+Version=\"([0-9]+.[0-9]+.[0-9]+)\".*" "\\1" SYSTEM_DRAWING_COMMON_VERSION "${EMGUCV_MODELS_NETSTANDARD_PROJECT_SYSTEM_DRAWING_COMMON}")
MESSAGE(STATUS "System.Drawing.Common = ${SYSTEM_DRAWING_COMMON_VERSION}")

SET(NUGET_SYSTEM_TEXT_JSON_VERSION "${SYSTEM_TEXT_JSON_VERSION}")
SET(NUGET_SYSTEM_DRAWING_COMMON_VERSION "${SYSTEM_DRAWING_COMMON_VERSION}")

#  SET(EMGUCV_NUGET_FILE_LIST "${EMGUCV_NUGET_FILE_LIST} 
#	<file src=\"..\\..\\..\\libs\\iOS\\Emgu.CV.dll\" target=\"lib\\${EMGUCV_MAUI_MACOS_DST_FOLDER}\" />
#    <file src=\"..\\..\\..\\libs\\iOS\\Emgu.CV.xml\" target=\"lib\\${EMGUCV_MAUI_MACOS_DST_FOLDER}\" />
#	<file src=\"..\\..\\..\\libs\\iOS\\Emgu.CV.dll\" target=\"lib\\${EMGUCV_MAUI_IOS_DST_FOLDER}\" />
#    <file src=\"..\\..\\..\\libs\\iOS\\Emgu.CV.xml\" target=\"lib\\${EMGUCV_MAUI_IOS_DST_FOLDER}\" />
#	")
#  SET(EMGUCV_NUGET_DEPENDENCY "${EMGUCV_NUGET_DEPENDENCY} 
#	  <group targetFramework=\"${EMGUCV_MAUI_MACOS_DST_FOLDER}\">
#        <dependency id=\"System.Drawing.Primitives\" version=\"4.3.0\" exclude=\"Build,Analyzers\" />
#        <dependency id=\"System.Runtime\" version=\"4.3.1\" exclude=\"Build,Analyzers\" />
#        <dependency id=\"System.Runtime.InteropServices.RuntimeInformation\" version=\"4.3.0\" exclude=\"Build,Analyzers\" />
#		<dependency id=\"System.Runtime.InteropServices.NFloat.Internal\" version=\"6.0.1\" exclude=\"Build,Analyzers\" />
#      </group>
#	  <group targetFramework=\"${EMGUCV_MAUI_IOS_DST_FOLDER}\">
#        <dependency id=\"System.Drawing.Primitives\" version=\"4.3.0\" exclude=\"Build,Analyzers\" />
#        <dependency id=\"System.Runtime\" version=\"4.3.1\" exclude=\"Build,Analyzers\" />
#        <dependency id=\"System.Runtime.InteropServices.RuntimeInformation\" version=\"4.3.0\" exclude=\"Build,Analyzers\" />
#		<dependency id=\"System.Runtime.InteropServices.NFloat.Internal\" version=\"6.0.1\" exclude=\"Build,Analyzers\" />
#      </group>")


#SET(EMGUCV_NUGET_FILE_LIST "${EMGUCV_NUGET_FILE_LIST} 
#    <file src=\"..\\..\\..\\libs\\Emgu.CV.dll\" target=\"lib\\netstandard2.0\" />
#    <file src=\"..\\..\\..\\libs\\Emgu.CV.xml\" target=\"lib\\netstandard2.0\" />
#    <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
#    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />
#	<file src=\"README.md\" target=\"docs\\\" />")
#SET(EMGUCV_NUGET_DEPENDENCY "${EMGUCV_NUGET_DEPENDENCY} 
#      <group targetFramework=\".NETStandard2.0\">
#        <dependency id=\"System.Drawing.Primitives\" version=\"4.3.0\" exclude=\"Build,Analyzers\" />
#        <dependency id=\"System.Runtime\" version=\"4.3.1\" exclude=\"Build,Analyzers\" />
#        <dependency id=\"System.Runtime.InteropServices.RuntimeInformation\" version=\"4.3.0\" exclude=\"Build,Analyzers\" />
#		<dependency id=\"System.Text.Json\" version=\"${NUGET_SYSTEM_TEXT_JSON_VERSION}\" exclude=\"Build,Analyzers\" />
#      </group>")


SET(EMGUCV_BITMAP_NUGET_TITLE "Bitmap extension for Emgu CV")
SET(EMGUCV_BITMAP_NUGET_SUMMARY "This package add extension method to convert Bitmap to and from Emgu objects (e.g. Mat, UMat, GpuMat)")
SET(EMGUCV_BITMAP_NUGET_FILE_LIST "")
SET(EMGUCV_BITMAP_NUGET_DEPENDENCY "")
SET(EMGUCV_BITMAP_NUGET_FILE_LIST "${EMGUCV_BITMAP_NUGET_FILE_LIST} 
    <file src=\"..\\..\\..\\libs\\Emgu.CV.Bitmap.dll\" target=\"lib\\netstandard2.0\" />
    <file src=\"..\\..\\..\\libs\\Emgu.CV.Bitmap.xml\" target=\"lib\\netstandard2.0\" />
    <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />
	<file src=\"README.md\" target=\"docs\\\" />")
SET(EMGUCV_BITMAP_NUGET_DEPENDENCY "${EMGUCV_BITMAP_NUGET_DEPENDENCY} 
      <group targetFramework=\".NETStandard2.0\">
        <dependency id=\"System.Drawing.Common\" version=\"${NUGET_SYSTEM_DRAWING_COMMON_VERSION}\" exclude=\"Build,Analyzers\" />
        <dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
      </group>")
SET(EMGUCV_BITMAP_NUGET_DEPENDENCY "
	<dependencies>
${EMGUCV_BITMAP_NUGET_DEPENDENCY}
    </dependencies>")
	
SET(EMGUCV_WPF_NUGET_TITLE "WPF extension for Emgu CV")
SET(EMGUCV_WPF_NUGET_SUMMARY "This package add extension method to convert BitmapSource to and from Emgu objects (e.g. Mat)")
SET(EMGUCV_WPF_NUGET_FILE_LIST "")
	
SET(EMGUCV_MODELS_NUGET_TITLE "Experimental component to help download, initialize and execute image processing/AI models.")
SET(EMGUCV_MODELS_NUGET_SUMMARY "Experimental component to help download, initialize and execute image processing/AI models. This is under active development and API may change from time to time.")
SET(EMGUCV_MODELS_NUGET_FILE_LIST "")
SET(EMGUCV_MODELS_NUGET_DEPENDENCY "")

#IF (HAVE_IOS)
  #SET(EMGUCV_MODELS_NUGET_FILE_LIST "${EMGUCV_MODELS_NUGET_FILE_LIST} 
#	<file src=\"..\\..\\..\\libs\\iOS\\Emgu.CV.Models.dll\" target=\"lib\\${EMGUCV_MAUI_MACOS_DST_FOLDER}\" />
#    <file src=\"..\\..\\..\\libs\\iOS\\Emgu.CV.Models.xml\" target=\"lib\\${EMGUCV_MAUI_MACOS_DST_FOLDER}\" />
#	<file src=\"..\\..\\..\\libs\\iOS\\Emgu.CV.Models.dll\" target=\"lib\\${EMGUCV_MAUI_IOS_DST_FOLDER}\" />
#    <file src=\"..\\..\\..\\libs\\iOS\\Emgu.CV.Models.xml\" target=\"lib\\${EMGUCV_MAUI_IOS_DST_FOLDER}\" />
#	")
#  SET(EMGUCV_MODELS_NUGET_DEPENDENCY "${EMGUCV_MODELS_NUGET_DEPENDENCY}
#	  <group targetFramework=\"${EMGUCV_MAUI_MACOS_DST_FOLDER}\">
#        <dependency id=\"System.Drawing.Common\" version=\"${NUGET_SYSTEM_DRAWING_COMMON_VERSION}\" exclude=\"Build,Analyzers\" />
#        <dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
#      </group>
#	  <group targetFramework=\"${EMGUCV_MAUI_IOS_DST_FOLDER}\">
#        <dependency id=\"System.Drawing.Common\" version=\"${NUGET_SYSTEM_DRAWING_COMMON_VERSION}\" exclude=\"Build,Analyzers\" />
#        <dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
#      </group>")
#ENDIF()

#SET(EMGUCV_MODELS_NUGET_FILE_LIST "${EMGUCV_MODELS_NUGET_FILE_LIST} 
#    <file src=\"..\\..\\..\\libs\\Emgu.CV.Models.dll\" target=\"lib\\netstandard2.0\" />
#    <file src=\"..\\..\\..\\libs\\Emgu.CV.Models.xml\" target=\"lib\\netstandard2.0\" />
#    <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
#    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />
#	<file src=\"README.md\" target=\"docs\\\" />")
#SET(EMGUCV_MODELS_NUGET_DEPENDENCY "${EMGUCV_MODELS_NUGET_DEPENDENCY} 
#      <group targetFramework=\".NETStandard2.0\">
#        <dependency id=\"System.Drawing.Common\" version=\"${NUGET_SYSTEM_DRAWING_COMMON_VERSION}\" exclude=\"Build,Analyzers\" />
#        <dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
#      </group>")
#SET(EMGUCV_MODELS_NUGET_DEPENDENCY "
#	<dependencies>
#${EMGUCV_MODELS_NUGET_DEPENDENCY}
#    </dependencies>")


IF (HAVE_WINDESKTOP_X64 OR HAVE_WINDESKTOP_X86 OR HAVE_WINDESKTOP_ARM64)
  #SET(EMGU_WINDOWS_MSVCRT_VERSION ${MSVC_TOOLSET_VERSION})
  IF(MSVC)
    SET(EMGU_WINDOWS_MSVCRT_VERSION ${CMAKE_CXX_COMPILER_VERSION})
	string(REPLACE "." ";" EMGU_WINDOWS_MSVCRT_VERSION_LIST ${EMGU_WINDOWS_MSVCRT_VERSION})
	list(GET EMGU_WINDOWS_MSVCRT_VERSION_LIST 0 EMGU_WINDOWS_MSVCRT_VERSION_MAJOR)
	list(GET EMGU_WINDOWS_MSVCRT_VERSION_LIST 1 EMGU_WINDOWS_MSVCRT_VERSION_MINOR)
	list(GET EMGU_WINDOWS_MSVCRT_VERSION_LIST 2 EMGU_WINDOWS_MSVCRT_VERSION_PATCH)
	list(GET EMGU_WINDOWS_MSVCRT_VERSION_LIST 3 EMGU_WINDOWS_MSVCRT_VERSION_BUILD)
	MESSAGE(STATUS "MSVCRT VERSION: ${EMGU_WINDOWS_MSVCRT_VERSION_MAJOR}.${EMGU_WINDOWS_MSVCRT_VERSION_MINOR}.${EMGU_WINDOWS_MSVCRT_VERSION_PATCH}.${EMGU_WINDOWS_MSVCRT_VERSION_BUILD}")
    SET(EMGU_WINDOWS_MSVCRT_NUGET_VERSION ${EMGU_WINDOWS_MSVCRT_VERSION})
	IF ("${EMGU_WINDOWS_MSVCRT_VERSION_BUILD}" STREQUAL "0")
	  SET(EMGU_WINDOWS_MSVCRT_NUGET_VERSION "${EMGU_WINDOWS_MSVCRT_VERSION_MAJOR}.${EMGU_WINDOWS_MSVCRT_VERSION_MINOR}.${EMGU_WINDOWS_MSVCRT_VERSION_PATCH}")
	ENDIF()
	MESSAGE(STATUS "MSVCRT NUGET VERSION: ${EMGU_WINDOWS_MSVCRT_NUGET_VERSION}")
  ENDIF()
  
  SET(EMGUCV_UI_NUGET_TITLE "Windows UI components for Emgu CV")
#  SET(EMGUCV_UI_NUGET_FILE_LIST "${EMGUCV_UI_NUGET_FILE_LIST} 
#    <file src=\"..\\..\\..\\libs\\Emgu.CV.Platform.NetFramework.dll\" target=\"lib\\net461\" />
#    <file src=\"..\\..\\..\\libs\\Emgu.CV.Platform.NetFramework.xml\" target=\"lib\\net461\" />
#    <file src=\"..\\..\\..\\libs\\Emgu.CV.Platform.NetCore.dll\" target=\"lib\\netcoreapp3.1\" />
#    <file src=\"..\\..\\..\\libs\\Emgu.CV.Platform.NetCore.xml\" target=\"lib\\netcoreapp3.1\" />
#    <file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
#    <file src=\"..\\..\\..\\${EMGUCV_LICENSE_FILE}\" target=\"\" />
#	<file src=\"README.md\" target=\"docs\\\" />")
#  SET(EMGUCV_UI_NUGET_DEPENDENCY "${EMGUCV_UI_NUGET_DEPENDENCY}
#      <group targetFramework=\".NETFramework4.6.1\">
#        <dependency id=\"${EMGUCV_BITMAP_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
#      </group>")
#  SET(EMGUCV_UI_NUGET_DEPENDENCY "${EMGUCV_UI_NUGET_DEPENDENCY}
#      <group targetFramework=\".NETCoreApp3.1\">
#        <dependency id=\"${EMGUCV_BITMAP_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />
#      </group>")
#  SET(EMGUCV_UI_NUGET_DEPENDENCY "${EMGUCV_UI_NUGET_DEPENDENCY}
#    <frameworkReferences>
#      <group targetFramework=\".NETCoreApp3.1\">
#        <frameworkReference name=\"Microsoft.WindowsDesktop.App.WindowsForms\" />
#      </group>
#    </frameworkReferences>")
#  SET(EMGUCV_UI_NUGET_DEPENDENCY "
#	<dependencies>
#${EMGUCV_UI_NUGET_DEPENDENCY}
#    </dependencies>
#    <frameworkAssemblies>
#      <frameworkAssembly assemblyName=\"System.Windows.Forms\" targetFramework=\".NETFramework4.6.1\" />
#    </frameworkAssemblies>")
ENDIF()

#SET(EMGUCV_NUGET_DEPENDENCY "
#	<dependencies>
#${EMGUCV_NUGET_DEPENDENCY}
#    </dependencies>")

#SET(EMGUCV_NUGET_FRAMEWORK_REFERENCES "
#	<frameworkReferences>
#${EMGUCV_NUGET_FRAMEWORK_REFERENCES}
#    </frameworkReferences>")

SET(EMGUCV_NUGET_TITLE_ARCH "")
IF(HAVE_WINDESKTOP_X86)
 SET(EMGUCV_NUGET_TITLE_ARCH "${EMGUCV_NUGET_TITLE_ARCH} x86")
ENDIF()
IF(HAVE_WINDESKTOP_X64)
 SET(EMGUCV_NUGET_TITLE_ARCH "${EMGUCV_NUGET_TITLE_ARCH} x64")
ENDIF()
IF(HAVE_WINDESKTOP_ARM64)
 SET(EMGUCV_NUGET_TITLE_ARCH "${EMGUCV_NUGET_TITLE_ARCH} arm64")
ENDIF()
STRING(STRIP "${EMGUCV_NUGET_TITLE_ARCH}" EMGUCV_NUGET_TITLE_ARCH)
STRING(REPLACE "x86 x64 arm64" "" EMGUCV_NUGET_TITLE_ARCH "${EMGUCV_NUGET_TITLE_ARCH}")

SET(EMGUCV_WINDOWS_NUGET_DEPENDENCY "${EMGUCV_WINDOWS_NUGET_DEPENDENCY}<dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${NUGET_PACKAGE_DEPENDENCY_VERSION}\" />")
#SET(EMGUCV_WINDOWS_NETCORE_NUGET_DEPENDENCY "<dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />")
#SET(EMGUCV_WINDOWS_NETFRAMEWORK_NUGET_DEPENDENCY "<dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${CPACK_PACKAGE_DEPENDENCY_VERSION}\" />")
 
SET(EMGUCV_WINDOWS_NUGET_TITLE "EMGU CV ${EMGUCV_NUGET_TITLE_ARCH}")
#SET(EMGUCV_WINDOWS_NUGET_TITLE "EMGU CV ${EMGUCV_NUGET_TITLE_ARCH}")
STRING(STRIP "${EMGUCV_WINDOWS_NUGET_TITLE}" EMGUCV_WINDOWS_NUGET_TITLE)
SET(EMGUCV_WINDOWS_NUGET_TITLE "${EMGUCV_WINDOWS_NUGET_TITLE} runtime for windows")

SET(EMGUCV_MACOS_NUGET_DEPENDENCY "${EMGUCV_MACOS_NUGET_DEPENDENCY}<dependency id=\"${EMGUCV_NUGET_ID}\" version=\"${NUGET_PACKAGE_DEPENDENCY_VERSION}\" />")

SET(EMGUCV_MACOS_NUGET_TITLE "EMGU CV")
STRING(STRIP "${EMGUCV_MACOS_NUGET_TITLE}" EMGUCV_MACOS_NUGET_TITLE)
SET(EMGUCV_MACOS_NUGET_TITLE "${EMGUCV_MACOS_NUGET_TITLE} runtime for MacOS")

IF(WITH_CUDA)
    
	SET(EMGUCV_WINDOWS_NUGET_TITLE "${EMGUCV_WINDOWS_NUGET_TITLE} with CUDA support")
	SET(EMGU_CUDA_NUGET_TITLE "Native x64 CUDA dependency for EMGU CV")
	#SET(EMGU_CUDA_VERSION "${npp_major}.${npp_minor}.${npp_build}")
	IF ( (${cuda_major}) AND (${cuda_minor}) AND (${npp_build}) )
	  SET(EMGU_CUDA_VERSION "${cuda_major}.${cuda_minor}.${npp_build}")
	ELSEIF (${CUDA_VERSION} AND (${npp_build}) )
	  SET(EMGU_CUDA_VERSION "${CUDA_VERSION}.${npp_build}")
	ELSEIF (${CUDA_VERSION})
	  SET(EMGU_CUDA_VERSION "${CUDA_VERSION}")
	ENDIF()
	
	
	SET(EMGU_CUDART_VERSION "${EMGU_CUDA_VERSION}")
	SET(EMGU_CUDA_NUGET_DEPENDENCY_STR "${EMGU_CUDA_VERSION}")
	SET(EMGU_CUFFT_VERSION "${EMGU_CUDA_VERSION}")
	SET(EMGU_CUFFT_NUGET_TITLE "Native x64 FFT component for CUDA")
	SET(EMGU_CUDNN_VERSION "${CUDNN_VERSION_MAJOR}.${CUDNN_VERSION_MINOR}.${CUDNN_VERSION_PATCH}")
	IF ("${EMGU_CUDNN_VERSION}" STREQUAL "")
		MESSAGE(FATAL_ERROR "FAILED to detect DNN version")
	ENDIF()
	SET(EMGU_CUDNN_NUGET_DEPENDENCY_STR "${EMGU_CUDNN_VERSION}")
	SET(EMGU_CUDNN_NUGET_TITLE "Native x64 DNN component for CUDA")
	SET(EMGU_CUDNN_CNN_NUGET_TITLE "Native x64 CNN component for CUDA DNN")
	SET(EMGU_CUDNN_ENGINES_NUGET_TITLE "Native x64 CNN engines component for CUDA DNN")
	SET(EMGU_CUDNN_OPS_NUGET_TITLE "Native x64 OPS component for CUDA DNN")
	#SET(EMGU_CUDNN_CNN_INFER_NUGET_TITLE "Native x64 CNN component for CUDA DNN")
	#SET(EMGU_CUDNN_CNN_TRAIN_NUGET_TITLE "Native x64 CNN training component for CUDA DNN")
	SET(EMGU_NPP_VERSION "${EMGU_CUDA_VERSION}")
	SET(EMGU_CUDA_BLAS_VERSION "${EMGU_CUDA_VERSION}")
	SET(EMGU_NPP_NUGET_TITLE "Native x64 NPP component for CUDA")
	SET(EMGU_CUDA_BLAS_NUGET_TITLE "Native x64 blas component for CUDA")
	SET(EMGU_CUDA_BLAS_LT_NUGET_TITLE "Native x64 blas lt component for CUDA")
	
	IF(HAVE_WINDESKTOP_X64)
	    #SET(CUDA_EULA_URL https://docs.nvidia.com/pdf/EULA.pdf)
		#file(DOWNLOAD ${CUDA_EULA_URL} "${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.windows.cuda.npp/EULA.pdf")
		#file(DOWNLOAD ${CUDA_EULA_URL} "${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.windows.cuda.cufft/EULA.pdf")
		#file(COPY "${CUDA_TOOLKIT_ROOT_DIR}/EULA.txt" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Cudnn")
		SET(EMGU_CUDA_RT_NUGET_FILE_LIST "${EMGU_CUDA_RT_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cu*.dll\" exclude=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cufft*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\cublas*.dll\" target=\"runtimes\\win-x64\\native\" /> 
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />		
		<file src=\"EULA.txt\" target=\"CUDA_EULA.txt\" />")
		SET(EMGU_CUDA_NPP_NUGET_FILE_LIST "${EMGU_CUDA_NPP_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\npp*.dll\" target=\"runtimes\\win-x64\\native\" />
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />		
		<file src=\"EULA.txt\" target=\"CUDA_EULA.txt\" />")
		SET(EMGU_CUDA_BLAS_NUGET_FILE_LIST "${EMGU_CUDA_BLAS_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cublas64*.dll\" target=\"runtimes\\win-x64\\native\" />
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />		
		<file src=\"EULA.txt\" target=\"CUDA_EULA.txt\" />")
		SET(EMGU_CUDA_BLAS_LT_NUGET_FILE_LIST "${EMGU_CUDA_BLAS_LT_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cublasLt*.dll\" target=\"runtimes\\win-x64\\native\" />
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />		
		<file src=\"EULA.txt\" target=\"CUDA_EULA.txt\" />")
		SET(EMGU_CUFFT_NUGET_FILE_LIST "${EMGU_CUFFT_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cufft*.dll\" target=\"runtimes\\win-x64\\native\" />
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
		<file src=\"EULA.txt\" target=\"CUDA_EULA.txt\" />")
		SET(EMGU_CUDNN_NUGET_FILE_LIST "${EMGU_CUDNN_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn*.dll\" exclude=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn_engines*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn_ops*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn_cnn*.dll;..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn_adv*.dll\" target=\"runtimes\\win-x64\\native\" />
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
		<file src=\"NVIDIA_SLA_cuDNN_Support.txt\" target=\"cuDNN_SLA.txt\" />")

		SET(EMGU_CUDNN_CNN_NUGET_FILE_LIST "${EMGU_CUDNN_CNN_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn_cnn*.dll\" target=\"runtimes\\win-x64\\native\" />
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
		<file src=\"NVIDIA_SLA_cuDNN_Support.txt\" target=\"cuDNN_SLA.txt\" />")
		SET(EMGU_CUDNN_ENGINES_NUGET_FILE_LIST "${EMGU_CUDNN_ENGINES_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn_engines*.dll\" target=\"runtimes\\win-x64\\native\" />
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
		<file src=\"NVIDIA_SLA_cuDNN_Support.txt\" target=\"cuDNN_SLA.txt\" />")
		SET(EMGU_CUDNN_CNN_NUGET_DEPENDENCY "
		<dependencies>
		  <dependency id=\"${EMGU_CUDNN_NUGET_ID}\" version=\"${EMGU_CUDNN_NUGET_DEPENDENCY_STR}\" />
		</dependencies>")
		SET(EMGU_CUDNN_ENGINES_NUGET_DEPENDENCY "
		<dependencies>
		  <dependency id=\"${EMGU_CUDNN_NUGET_ID}\" version=\"${EMGU_CUDNN_NUGET_DEPENDENCY_STR}\" />
		</dependencies>")
		SET(EMGU_CUDNN_OPS_NUGET_FILE_LIST "${EMGU_CUDNN_OPS_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn_ops*.dll\" target=\"runtimes\\win-x64\\native\" />
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
		<file src=\"NVIDIA_SLA_cuDNN_Support.txt\" target=\"cuDNN_SLA.txt\" />")
		SET(EMGU_CUDNN_OPS_NUGET_DEPENDENCY "
		<dependencies>
		  <dependency id=\"${EMGU_CUDNN_NUGET_ID}\" version=\"${EMGU_CUDNN_NUGET_DEPENDENCY_STR}\" />
		</dependencies>")
		SET(EMGU_CUDNN_ADV_NUGET_FILE_LIST "${EMGU_CUDNN_ADV_NUGET_FILE_LIST} 
		<file src=\"..\\..\\..\\libs\\runtimes\\win-x64\\native\\cudnn_adv*.dll\" target=\"runtimes\\win-x64\\native\" />
		<file src=\"..\\..\\..\\miscellaneous\\nuget_icon.png\" target=\"icon.png\" />
		<file src=\"NVIDIA_SLA_cuDNN_Support.txt\" target=\"cuDNN_SLA.txt\" />")
		SET(EMGU_CUDNN_ADV_NUGET_DEPENDENCY "
		<dependencies>
		  <dependency id=\"${EMGU_CUDNN_NUGET_ID}\" version=\"${EMGU_CUDNN_NUGET_DEPENDENCY_STR}\" />
		</dependencies>")
		SET(EMGU_CUDNN_NUGET_DEPENDENCY "
		<dependencies>
		  <dependency id=\"${EMGU_CUDART_NUGET_ID}\" version=\"${EMGU_CUDA_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_ZLIBWAPI_ID}\" version=\"${EMGU_ZLIBWAPI_VERSION}\" />
		</dependencies>")
		SET(EMGUCV_WINDOWS_NUGET_DEPENDENCY "${EMGUCV_WINDOWS_NUGET_DEPENDENCY}
		  <dependency id=\"${EMGU_CUDART_NUGET_ID}\" version=\"${EMGU_CUDA_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_CUDA_BLAS_LT_NUGET_ID}\" version=\"${EMGU_CUDA_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_CUDA_BLAS_NUGET_ID}\" version=\"${EMGU_CUDA_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_NPP_NUGET_ID}\" version=\"${EMGU_CUDA_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_CUFFT_NUGET_ID}\" version=\"${EMGU_CUDA_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_CUDNN_ADV_NUGET_ID}\" version=\"${EMGU_CUDNN_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_CUDNN_CNN_NUGET_ID}\" version=\"${EMGU_CUDNN_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_CUDNN_ENGINES_NUGET_ID}\" version=\"${EMGU_CUDNN_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_CUDNN_OPS_NUGET_ID}\" version=\"${EMGU_CUDNN_NUGET_DEPENDENCY_STR}\" />
		  <dependency id=\"${EMGU_ZLIBWAPI_ID}\" version=\"${EMGU_ZLIBWAPI_VERSION}\" />
		  ")
		IF (WITH_CUDNN)
		  SET(EMGUCV_WINDOWS_NUGET_DEPENDENCY "${EMGUCV_WINDOWS_NUGET_DEPENDENCY}<dependency id=\"${EMGU_CUDNN_NUGET_ID}\" version=\"${EMGU_CUDNN_NUGET_DEPENDENCY_STR}\" />")
	    ENDIF()
	ENDIF()
	
	SET(NUGET_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")

	MESSAGE(STATUS "<<<<<<<<<<<<<<<< npp_major: ${npp_major} >>>>>>>>>>>>>>>>>>>>>> ")
	MESSAGE(STATUS "<<<<<<<<<<<<<<<< npp_minor: ${npp_minor} >>>>>>>>>>>>>>>>>>>>>> ")
	MESSAGE(STATUS "<<<<<<<<<<<<<<<< npp_build: ${npp_build} >>>>>>>>>>>>>>>>>>>>>> ")
	MESSAGE(STATUS "<<<<<<<<<<<<<<<< cuda_major: ${cuda_major} >>>>>>>>>>>>>>>>>>>>>> ")
	MESSAGE(STATUS "<<<<<<<<<<<<<<<< cuda_minor: ${cuda_minor} >>>>>>>>>>>>>>>>>>>>>> ")
	MESSAGE(STATUS "<<<<<<<<<<<<<<<< CUDA_VERSION: ${CUDA_VERSION} >>>>>>>>>>>>>>>>>>>>>> ")
	#MESSAGE(STATUS "<<<<<<<<<<<<<<<< CUDA_VERSION_MAJOR: ${CUDA_VERSION_MAJOR} >>>>>>>>>>>>>>>>>>>>>> ")
	#MESSAGE(STATUS "<<<<<<<<<<<<<<<< CUDA_VERSION_MINOR: ${CUDA_VERSION_MINOR} >>>>>>>>>>>>>>>>>>>>>> ")
	#MESSAGE(STATUS "<<<<<<<<<<<<<<<< cuda_build: ${cuda_build} >>>>>>>>>>>>>>>>>>>>>> ")
    MESSAGE(STATUS "<<<<<<<<<<<<<<<< cudnn_version_major: ${CUDNN_VERSION_MAJOR} >>>>>>>>>>>>>>>>>>>>>> ")
	MESSAGE(STATUS "<<<<<<<<<<<<<<<< cudnn_version_minor: ${CUDNN_VERSION_MINOR} >>>>>>>>>>>>>>>>>>>>>> ")
	MESSAGE(STATUS "<<<<<<<<<<<<<<<< cudnn_version_patch: ${CUDNN_VERSION_PATCH} >>>>>>>>>>>>>>>>>>>>>> ")
	MESSAGE(STATUS "<<<<<<<<<<<<<<<< EMGU_CUDA_VERSION: ${EMGU_CUDA_VERSION} >>>>>>>>>>>>>>>>>>>>>> ")

	#IF ("${npp_major}" STREQUAL "")
	#  MESSAGE(FATAL_ERROR "CUDA is enabled, but failed to detect npp_major version")
	#ENDIF()
	#IF ("${npp_minor}" STREQUAL "")
	#  MESSAGE(FATAL_ERROR "CUDA is enabled, but failed to detect npp_minor version")
	#ENDIF()
	#IF ("${npp_build}" STREQUAL "")
	#  MESSAGE(FATAL_ERROR "CUDA is enabled, but failed to detect npp_build version")
	#ENDIF()
	
	
	IF ( (${cuda_major}) AND (${cuda_minor}) )
	  SET(CUDA_VERSION_NUMERIC_ONLY "${cuda_major}${cuda_minor}")
	ELSE()
	  SET(CUDA_VERSION_NUMERIC_ONLY "${npp_major}${npp_minor}")
	ENDIF()

	IF(WIN32)
	  IF((${npp_major} GREATER 10) OR (("${npp_major}" STREQUAL "10") AND (${npp_minor} GREATER 0)))
	    IF (${cuda_major})
	      SET(CUFFT_POSTFIX "${cuda_major}")
	    else()
	      SET(CUFFT_POSTFIX "${npp_major}")
	    endif()
	  ELSE()
	    SET(CUFFT_POSTFIX "${npp_major}${npp_minor}")
	  ENDIF()
	ENDIF()
	
	#MESSAGE(STATUS "<<<<<<<<<<<<<<<< CUDA_VERSION_NUMERIC_ONLY: ${CUDA_VERSION_NUMERIC_ONLY} >>>>>>>>>>>>>>>>>>>>>> ")
	
	#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.windows.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.windows/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_ZLIBWAPI_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_ZLIBWAPI_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_CUFFT_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_CUFFT_NUGET_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_CUDNN_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_CUDNN_NUGET_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_CUDNN_ADV_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_CUDNN_ADV_NUGET_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_CUDNN_CNN_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_CUDNN_CNN_NUGET_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_CUDNN_ENGINES_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_CUDNN_ENGINES_NUGET_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_CUDNN_OPS_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_CUDNN_OPS_NUGET_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_NPP_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_NPP_NUGET_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_CUDART_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_CUDART_NUGET_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_CUDA_BLAS_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_CUDA_BLAS_NUGET_ID}/Package.nuspec)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_CUDA_BLAS_LT_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_CUDA_BLAS_LT_NUGET_ID}/Package.nuspec)
ENDIF()

IF(HAVE_WINDESKTOP_X86)
  SET(EMGUCV_WINDOWS_NUGET_DEPENDENCY "${EMGUCV_WINDOWS_NUGET_DEPENDENCY}
	  <dependency id=\"${EMGU_WINDOWS_MSVCRT_X86_NUGET_ID}\" version=\"${EMGU_WINDOWS_MSVCRT_VERSION}\" />
	  ")		
ENDIF()

IF(HAVE_WINDESKTOP_X64)
  SET(EMGUCV_WINDOWS_NUGET_DEPENDENCY "${EMGUCV_WINDOWS_NUGET_DEPENDENCY}
	  <dependency id=\"${EMGU_WINDOWS_MSVCRT_X64_NUGET_ID}\" version=\"${EMGU_WINDOWS_MSVCRT_VERSION}\" />
	  ")		
ENDIF()

IF(HAVE_WINDESKTOP_ARM64)
  SET(EMGUCV_WINDOWS_NUGET_DEPENDENCY "${EMGUCV_WINDOWS_NUGET_DEPENDENCY}
	  <dependency id=\"${EMGU_WINDOWS_MSVCRT_ARM64_NUGET_ID}\" version=\"${EMGU_WINDOWS_MSVCRT_VERSION}\" />
	  ")		
ENDIF()

SET(EMGUCV_WINDOWS_NUGET_DEPENDENCY "	<dependencies>
		${EMGUCV_WINDOWS_NUGET_DEPENDENCY}
    </dependencies>")

SET(EMGUCV_MACOS_NUGET_DEPENDENCY "	<dependencies>
		${EMGUCV_MACOS_NUGET_DEPENDENCY}
    </dependencies>")

# Sign the binary
  SET(EMGUCV_POST_PROCESS_BINARY "")
  IF(EMGU_SIGN_FOUND AND WIN32)    
    file(TO_NATIVE_PATH ${EMGU_SIGN_EXECUTABLE} EMGU_SIGN_EXECUTABLE_NATIVE_PATH)
    file(TO_NATIVE_PATH ${SIGNTOOL_EXECUTABLE} SIGNTOOL_EXECUTABLE_NATIVE_PATH)
    SET(EMGUCV_POST_PROCESS_BINARY "${EMGUCV_POST_PROCESS_BINARY}
    <Target Name=\"PostProcessBinary\" AfterTargets=\"PostBuildEvent\" Condition=\"Exists('${EMGU_SIGN_EXECUTABLE_NATIVE_PATH}')\">
      <Message Text=\"Signing $(OutputPath)$(AssemblyName).dll\" Importance=\"high\" />
      <MakeDir Directories=\"$(OutputPath)\\signed\"/>
      <Exec Command='${EMGU_SIGN_EXECUTABLE_NATIVE_PATH} \"$(OutputPath)$(AssemblyName).dll\" \"$(OutputPath)signed\" \"${SIGNTOOL_EXECUTABLE_NATIVE_PATH}\"' WorkingDirectory=\"$(OutputPath)\" />
    </Target>")
  ENDIF()  

# Sign the debugger visualizer
  SET(EMGUCV_POST_PROCESS_VSIX "")
  IF(EMGU_VSIX_SIGN_FOUND AND WIN32)
    file(TO_NATIVE_PATH ${EMGU_VSIX_SIGN_EXECUTABLE} EMGU_VSIX_SIGN_EXECUTABLE_NATIVE_PATH)
	file(TO_NATIVE_PATH ${OPENVSIXSIGNTOOL_EXECUTABLE} OPENVSIXSIGNTOOL_EXECUTABLE_NATIVE_PATH)
    SET(EMGUCV_POST_PROCESS_VSIX "${EMGUCV_POST_PROCESS_VSIX}
    <Target Name=\"PostProcessVSIX\" AfterTargets=\"PostBuildEvent\" Condition=\"Exists('${EMGU_SIGN_EXECUTABLE_NATIVE_PATH}')\">
      <Message Text=\"Signing $(OutputPath)$(AssemblyName).vsix\" Importance=\"high\" />
      <MakeDir Directories=\"$(OutputPath)\\signed\"/>
      <Exec Command='${EMGU_VSIX_SIGN_EXECUTABLE_NATIVE_PATH} \"$(OutputPath)$(AssemblyName).vsix\" \"$(OutputPath)signed\" \"${OPENVSIXSIGNTOOL_EXECUTABLE_NATIVE_PATH}\"' WorkingDirectory=\"$(OutputPath)\" />
    </Target>")
  ENDIF()  
  
  # Generate nuget config file for Emgu.CV.Bitmap
# Sign and copy the binary
SET(EMGUCV_POST_PROCESS_NUGET "")
IF(EMGU_SIGN_FOUND AND WIN32)
  file(TO_NATIVE_PATH ${EMGU_SIGN_EXECUTABLE} EMGU_SIGN_EXECUTABLE_NATIVE_PATH)
  file(TO_NATIVE_PATH ${SIGNTOOL_EXECUTABLE} SIGNTOOL_EXECUTABLE_NATIVE_PATH)
  SET(EMGUCV_POST_PROCESS_NUGET "
  <Target Name=\"PostProcessNuget\" AfterTargets=\"Pack\">
    <Message Text=\"Signing $(PackageOutputPath)\\$(PackageId).$(PackageVersion).nupkg\" Importance=\"high\" />
    <MakeDir Directories=\"$(PackageOutputPath)\\signed\"/>
    <Exec Command='${EMGU_NUGET_SIGN_EXECUTABLE_NATIVE_PATH} \"$(PackageOutputPath)\\$(PackageId).$(PackageVersion).nupkg\" \"$(PackageOutputPath)\\signed\" \"${NUGET_EXECUTABLE_NATIVE_PATH}\"' WorkingDirectory=\"$(PackageOutputPath)\" />
  </Target>
	")
ENDIF()

#IF(HAVE_ANDROID)
  SET(EMGUCV_MAUI_ANDROID_NUGET_TITLE "Emgu CV for MAUI Android Native Runtime")
  
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.android.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/Android/Directory.Build.props)
  IF(EMGU_SIGN_FOUND AND WIN32)
    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignBinary.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/Android/SignBinary.Targets)
  ENDIF()
  IF(EMGU_NUGET_SIGN_FOUND AND WIN32)
    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignPkg.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/Android/SignPkg.Targets)
  ENDIF()
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.android.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/Android/docs/README.md)
#ENDIF()

#IF(HAVE_IOS)  
  SET(EMGUCV_MAUI_IOS_NUGET_TITLE "Emgu CV for MAUI iOS Native Runtime")	
  #SET(EMGUCV_MAUI_IOS_POST_PROCESS_BINARY "${EMGUCV_MAUI_IOS_POST_PROCESS_BINARY}")
  #SET(EMGUCV_MAUI_IOS_POST_PROCESS_BINARY "${EMGUCV_MAUI_IOS_POST_PROCESS_BINARY}
  #<Target Name=\"PostProcessBinary\" AfterTargets=\"PostBuildEvent\">
  #  <Message Text=\"Copying $(OutputPath)$(AssemblyName).dll, $(OutputPath)$(AssemblyName).xml to $(OpenCVBinaryDir)\" Importance=\"high\" />
  #  <Copy SourceFiles=\"$(OutputPath)$(AssemblyName).dll\" DestinationFolder=\"$(OpenCVBinaryDir)\" ContinueOnError=\"true\" />
  #  <Copy SourceFiles=\"$(OutputPath)$(AssemblyName).xml\" DestinationFolder=\"$(OpenCVBinaryDir)\" ContinueOnError=\"true\" />
  #</Target>")  
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.ios.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/iOS/Directory.Build.props)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.ios.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/iOS/docs/README.md)  
#ENDIF()

  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseRidGraph.props.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.macos/Emgu.CV.runtime.macos.props)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.macos.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.macos/Package.nuspec)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.macos.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.macos/docs/README.md)  


#IF(HAVE_MAUI)
  SET(EMGUCV_MAUI_NUGET_ID "${EMGUCV_NUGET_ID}.runtime.maui${EMGUCV_RUNTIME_EXTRA_TAG}")
  SET(EMGUCV_MAUI_NUGET_TITLE "Emgu CV for MAUI Native Runtime")
  
  SET(EMGUCV_MAUI_PACKAGE_REFERENCE "")
  IF (HAVE_WINDESKTOP)
    SET(EMGUCV_MAUI_PACKAGE_REFERENCE "
	<ItemGroup>
      <PackageReference Condition=\"$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'\" Include=\"${EMGUCV_WINDOWS_NUGET_ID}\" Version=\"${CPACK_PACKAGE_VERSION}\">
	  </PackageReference>
    </ItemGroup>")
  ENDIF()
  
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/UI/Directory.Build.props)
  IF(EMGU_SIGN_FOUND AND WIN32)
    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignBinary.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/UI/SignBinary.Targets)
  ENDIF()
  IF(EMGU_NUGET_SIGN_FOUND AND WIN32)
    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignPkg.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/UI/SignPkg.Targets)
  ENDIF()
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Runtime/Maui/UI/docs/README.md)
  #CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.maui/README.md)
  #CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.maui.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.maui/Package.nuspec)
#ENDIF()

IF (HAVE_WINDESKTOP)
  SET(EMGUCV_DEBUGGER_VISUALIZER_PACKAGE_REFERENCE "
	<ItemGroup>
      <PackageReference Condition=\"$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'\" Include=\"${EMGUCV_WINDOWS_NUGET_ID}\" Version=\"${CPACK_PACKAGE_VERSION}\">
	  </PackageReference>
	  <!--
	  <PackageReference Condition=\"$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'\" Include=\"${EMGUCV_WPF_NUGET_ID}\" Version=\"${CPACK_PACKAGE_VERSION}\">
	  </PackageReference>
	  -->
    </ItemGroup>")
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.DebuggerVisualizer.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/DebuggerVisualizer/Directory.Build.props)
  IF(EMGU_SIGN_FOUND AND WIN32)
    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignBinary.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/DebuggerVisualizer/SignBinary.Targets)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignVSIX.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/DebuggerVisualizer/SignVSIX.Targets)
  ENDIF()
ENDIF()

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.BuildInfo.Console.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Example/BuildInfo.Console/Directory.Build.props)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Test.Net.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Test/Emgu.CV.Test.Net/Directory.Build.props)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.DynamicImage.Asp.Net.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Example/DynamicImage.Asp.Net/Directory.Build.props)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.HelloWorld.Console.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Example/HelloWorld/Directory.Build.props)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.HelloWorld.WPF.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Example/HelloWorld.WPF/Directory.Build.props)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Maui.Demo.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Example/MAUI/MauiDemoApp/Directory.Build.props)

IF(HAVE_WINSTORE_10)
  SET(EMGUCV_UWP_NUGET_TITLE "Emgu CV for UWP Native Runtime")
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.uwp.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.uwp/Package.nuspec)
ENDIF()

IF(HAVE_WINDESKTOP_X86)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_WINDOWS_MSVCRT_X86_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_WINDOWS_MSVCRT_X86_NUGET_ID}/Package.nuspec)
ENDIF()

IF(HAVE_WINDESKTOP_X64)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_WINDOWS_MSVCRT_X64_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_WINDOWS_MSVCRT_X64_NUGET_ID}/Package.nuspec)
ENDIF()

IF(HAVE_WINDESKTOP_ARM64)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EMGU_WINDOWS_MSVCRT_ARM64_NUGET_ID}.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/${EMGU_WINDOWS_MSVCRT_ARM64_NUGET_ID}/Package.nuspec)  
ENDIF()

IF(HAVE_WINDESKTOP_X86 OR HAVE_WINDESKTOP_X64 OR HAVE_WINDESKTOP_ARM64)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.windows.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.windows/Package.nuspec)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.windows.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.windows/README.md)
  
  # Generate nuget config file for Emgu.CV.UI
  # Sign and copy the binary
  #SET(EMGUCV_UI_POST_PROCESS_BINARY "")
  #IF(EMGU_SIGN_FOUND AND WIN32)
  #  file(TO_NATIVE_PATH ${EMGU_SIGN_EXECUTABLE} EMGU_SIGN_EXECUTABLE_NATIVE_PATH)
  #  file(TO_NATIVE_PATH ${SIGNTOOL_EXECUTABLE} SIGNTOOL_EXECUTABLE_NATIVE_PATH)
  #  SET(EMGUCV_UI_POST_PROCESS_BINARY "
#	<Target Name=\"PostProcessBinary\" AfterTargets=\"PostBuildEvent\" Condition=\"Exists('${EMGU_SIGN_EXECUTABLE_NATIVE_PATH}')\">
#      <Message Text=\"Signing $(OutputPath)$(AssemblyName).dll\" Importance=\"high\" />
#  	  <MakeDir Directories=\"$(OutputPath)\\signed\"/>
#      <Exec Command='${EMGU_SIGN_EXECUTABLE_NATIVE_PATH} \"$(OutputPath)$(AssemblyName).dll\" \"$(OutputPath)signed\" \"${SIGNTOOL_EXECUTABLE_NATIVE_PATH}\"' WorkingDirectory=\"$(OutputPath)\" />
#  	</Target>
#  	")
#  ENDIF()
  
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.UI.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.WindowsUI/Emgu.CV.WindowsUI/Directory.Build.props)
  IF(EMGU_SIGN_FOUND AND WIN32)
    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignBinary.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.WindowsUI/Emgu.CV.WindowsUI/SignBinary.Targets)
  ENDIF()
  IF(EMGU_NUGET_SIGN_FOUND AND WIN32)
    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignPkg.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.WindowsUI/Emgu.CV.WindowsUI/SignPkg.Targets)
  ENDIF()
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.UI.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.WindowsUI/Emgu.CV.WindowsUI/docs/README.md)
ENDIF()

IF(HAVE_LINUX_ARM)
  SET(EMGUCV_DEBIAN_ARM_NUGET_TITLE "Emgu CV Native ARM Runtime for Debian (including Raspberry Pi OS)")
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseRidGraph.props.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.debian-arm/Emgu.CV.runtime.debian-arm.props)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.debian-arm.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.debian-arm/Package.nuspec)
ENDIF()

IF(HAVE_LINUX_ARM64)
  SET(EMGUCV_DEBIAN_ARM64_NUGET_TITLE "Emgu CV Native ARM64 Runtime for Debian (including Raspberry Pi OS)")
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseRidGraph.props.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.debian-arm64/Emgu.CV.runtime.debian-arm64.props)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.debian-arm64.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.debian-arm64/Package.nuspec)
ENDIF()

IF(HAVE_UBUNTU_X86 OR HAVE_UBUNTU_X64 OR HAVE_UBUNTU_ARM64)
  SET(EMGUCV_UBUNTU_NUGET_TITLE "Emgu CV Native Runtime for Ubuntu")
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseRidGraph.props.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.ubuntu/Emgu.CV.runtime.ubuntu.props)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.ubuntu.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.ubuntu/Package.nuspec)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.ubuntu.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.ubuntu/README.md)
ENDIF()

IF(HAVE_RHEL_X86 OR HAVE_RHEL_X64 OR HAVE_RHEL_ARM64)
  SET(EMGUCV_RHEL_NUGET_TITLE "Emgu CV Native Runtime for RHEL")
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.rhel.Package.nuspec.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.rhel/Package.nuspec)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseRidGraph.props.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.rhel/Emgu.CV.runtime.rhel.props)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.runtime.rhel.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/platforms/nuget/Emgu.CV.runtime.rhel/README.md)
ENDIF()

SET(EMGUCV_NUGET_TITLE "Emgu CV")
SET(EMGUCV_NUGET_SUMMARY "Emgu CV is a cross platform .Net wrapper to the OpenCV image processing library.")

IF ("${LICENSE_TYPE}" STREQUAL "Commercial")
	SET(EMGUCV_NUGET_TITLE "${EMGUCV_NUGET_TITLE} Commercial Release")
	SET(EMGUCV_NUGET_SUMMARY "${EMGUCV_NUGET_SUMMARY} This is the commercial release.")
	IF(HAVE_ANDROID)
      SET(EMGUCV_MAUI_ANDROID_NUGET_TITLE "${EMGUCV_MAUI_ANDROID_NUGET_TITLE} Commercial Release for MAUI")	  
	ENDIF()	
	IF(HAVE_WINSTORE_10)
	  SET(EMGUCV_UWP_NUGET_TITLE "${EMGUCV_UWP_NUGET_TITLE} Commercial Release")
	ENDIF()
ENDIF()



#generate nuget config file for Emgu.CV 
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV/NetStandard/Directory.Build.props)
IF(EMGU_SIGN_FOUND AND WIN32)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignBinary.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV/NetStandard/SignBinary.Targets)
ENDIF()
IF(EMGU_NUGET_SIGN_FOUND AND WIN32)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignPkg.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV/NetStandard/SignPkg.Targets)
ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV/NetStandard/docs/README.md)

#generate nuget config file for Emgu.CV.Models
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Models.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Models/NetStandard/Directory.Build.props)
IF(EMGU_SIGN_FOUND AND WIN32)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignBinary.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Models/NetStandard/SignBinary.Targets)
ENDIF()
IF(EMGU_NUGET_SIGN_FOUND AND WIN32)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignPkg.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Models/NetStandard/SignPkg.Targets)
ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Models.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Models/NetStandard/docs/README.md)


      
# Sign the nuget package
#SET(EMGUCV_BITMAP_POST_PROCESS_NUGET "")
#IF(EMGU_NUGET_SIGN_FOUND AND WIN32)
#  file(TO_NATIVE_PATH ${EMGU_NUGET_SIGN_EXECUTABLE} EMGU_NUGET_SIGN_EXECUTABLE_NATIVE_PATH)
#  file(TO_NATIVE_PATH ${NUGET_EXECUTABLE} NUGET_EXECUTABLE_NATIVE_PATH)
#  SET(EMGUCV_BITMAP_POST_PROCESS_NUGET "${EMGUCV_BITMAP_POST_PROCESS_NUGET}
#  <Target Name=\"PostProcessNuget\" AfterTargets=\"Pack\">
#    <Message Text=\"Signing $(PackageOutputPath)\\$(PackageId).$(PackageVersion).nupkg\" Importance=\"high\" />
#    <MakeDir Directories=\"$(PackageOutputPath)\\signed\"/>
#    <Exec Command='${EMGU_NUGET_SIGN_EXECUTABLE_NATIVE_PATH} \"$(PackageOutputPath)\\$(PackageId).$(PackageVersion).nupkg\" \"$(PackageOutputPath)\\signed\" \"${NUGET_EXECUTABLE_NATIVE_PATH}\"' WorkingDirectory=\"$(PackageOutputPath)\" />
#  </Target>
#	")
#ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Bitmap.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Bitmap/Directory.Build.props)
IF(EMGU_SIGN_FOUND AND WIN32)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignBinary.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Bitmap/SignBinary.Targets)
ENDIF()
IF(EMGU_NUGET_SIGN_FOUND AND WIN32)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignPkg.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Bitmap/SignPkg.Targets)
ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Bitmap.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Bitmap/docs/README.md)


#generate nuget config file for Emgu.CV.Wpf
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Wpf.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Wpf/Directory.Build.props)
IF(EMGU_SIGN_FOUND AND WIN32)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignBinary.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Wpf/SignBinary.Targets)
ENDIF()
IF(EMGU_NUGET_SIGN_FOUND AND WIN32)
  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignPkg.Targets.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Wpf/SignPkg.Targets)
ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.CV.Wpf.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Wpf/docs/README.md)

# Generate nuget config file for Emgu.CV.Wpf
# Sign and copy the binary
#SET(EMGUCV_WPF_POST_PROCESS_BINARY "")
#IF(EMGU_SIGN_FOUND AND WIN32)
#  file(TO_NATIVE_PATH ${EMGU_SIGN_EXECUTABLE} EMGU_SIGN_EXECUTABLE_NATIVE_PATH)
#  file(TO_NATIVE_PATH ${SIGNTOOL_EXECUTABLE} SIGNTOOL_EXECUTABLE_NATIVE_PATH)
#  SET(EMGUCV_WPF_POST_PROCESS_BINARY "
#  <Target Name=\"PostProcessBinary\" AfterTargets=\"PostBuildEvent\" Condition=\"Exists('${EMGU_SIGN_EXECUTABLE_NATIVE_PATH}')\">
#    <Message Text=\"Signing $(OutputPath)$(AssemblyName).dll\" Importance=\"high\" />
#	<MakeDir Directories=\"$(OutputPath)\\signed\"/>
#    <Exec Command='${EMGU_SIGN_EXECUTABLE_NATIVE_PATH} \"$(OutputPath)$(AssemblyName).dll\" \"$(OutputPath)signed\" \"${SIGNTOOL_EXECUTABLE_NATIVE_PATH}\"' WorkingDirectory=\"$(OutputPath)\" />
#  </Target>
#	")
#ENDIF()

# ----------------------------------------------------------------------------
#  Generate readme file for Emgu CV project
# ----------------------------------------------------------------------------
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/README.txt.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV/README.txt)
INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV/README.txt" DESTINATION "." COMPONENT emgucv_source)

# ----------------------------------------------------------------------------
#  Include license file & nuget icon into package
# ----------------------------------------------------------------------------
INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt" DESTINATION "." COMPONENT emgucv_source)
INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/miscellaneous/nuget_icon.png" DESTINATION "miscellaneous/" COMPONENT emgucv_source)

# ----------------------------------------------------------------------------
#  Generate CvInvokeEntryPoints.cs file for Emgu CV project
# ----------------------------------------------------------------------------
SET(OPENCV_LIBRARY_OUTPUT_NAME_PREFIX "")
IF (APPLE)
  SET(OPENCV_LIBRARY_OUTPUT_NAME_POSTFIX ".${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}")
ELSE()
  SET(OPENCV_LIBRARY_OUTPUT_NAME_POSTFIX "")
ENDIF()

SET(OPENCV_LIBRARY_OUTPUT_NAMES )

FOREACH(OPENCV_MODULE_NAME ${OPENCV_MODULE_NAME_CANDIDATES})
  STRING (TOUPPER "${OPENCV_MODULE_NAME}" OPENCV_MODULE_NAME_UPPER)
  
  STRING (SUBSTRING "${OPENCV_MODULE_NAME}" 0 1 OPENCV_MODULE_NAME_FIRST_LETTER)
  STRING (TOUPPER "${OPENCV_MODULE_NAME_FIRST_LETTER}" OPENCV_MODULE_NAME_FIRST_LETTER_UPPER)
  STRING (SUBSTRING "${OPENCV_MODULE_NAME}" 1 -1 OPENCV_MODULE_NAME_REMAINDER)
  SET(OPENCV_MODULE_NAME_FIRST_LETTER_UPPER "${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}${OPENCV_MODULE_NAME_REMAINDER}")
  
  SET(OPENCV_OUTPUT_PROJ_TYPE "")
  IF(NOT (TARGET opencv_${OPENCV_MODULE_NAME}))
    SET(OPENCV_${OPENCV_MODULE_NAME_UPPER}_OUTPUT_NAME "")
  ELSE()
    #MESSAGE( STATUS "opencv_${OPENCV_MODULE_NAME} type: ${OPENCV_OUTPUT_PROJ_TYPE}")
    GET_TARGET_PROPERTY(OPENCV_OUTPUT_PROJ_TYPE opencv_${OPENCV_MODULE_NAME} TYPE)
    IF(NOT ("${OPENCV_OUTPUT_PROJ_TYPE}" STREQUAL "SHARED_LIBRARY"))
      SET(OPENCV_${OPENCV_MODULE_NAME_UPPER}_OUTPUT_NAME "")
    ELSE()
      GET_TARGET_PROPERTY(OPENCV_OUTPUT_NAME_TMP opencv_${OPENCV_MODULE_NAME} OUTPUT_NAME)
      SET(OPENCV_${OPENCV_MODULE_NAME_UPPER}_OUTPUT_NAME  ${OPENCV_LIBRARY_OUTPUT_NAME_PREFIX}${OPENCV_OUTPUT_NAME_TMP}${OPENCV_LIBRARY_OUTPUT_NAME_POSTFIX})
      LIST(APPEND OPENCV_LIBRARY_OUTPUT_NAMES ${OPENCV_${OPENCV_MODULE_NAME_UPPER}_OUTPUT_NAME})
      SET(ENTRYPOINT_MODULES_STRING "${ENTRYPOINT_MODULES_STRING}
      Opencv${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}Library,")
    ENDIF()
  ENDIF()
  
  IF(IOS)
    SET(ENTRYPOINT_CS_STRING "${ENTRYPOINT_CS_STRING} 
      /// <summary>
      /// The file name of the ${OPENCV_MODULE_NAME} library
      /// </summary>
      public const string Opencv${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}Library = \"__Internal\";")
  ELSEIF(((WIN32 AND NOT ANDROID) OR APPLE))
    IF(("${OPENCV_OUTPUT_PROJ_TYPE}" STREQUAL "SHARED_LIBRARY"))
      SET(ANDROID_ENTRYPOINT "opencv_${OPENCV_MODULE_NAME}")
      SET(MACOS_ENTRYPOINT "opencv_${OPENCV_MODULE_NAME}.${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}")
      SET(MACOS_UNITY_STANDALONE_ENTRYPOINT "@executable_path/../Plugins/emgucv.bundle/Contents/MacOS/lib${MACOS_ENTRYPOINT}.dylib")
      SET(MACOS_UNITY_EDITOR_ENTRYPOINT "Assets/Plugins/emgucv.bundle/Contents/MacOS/lib${MACOS_ENTRYPOINT}.dylib")
      SET(WINDOWS_ENTRYPOINT "opencv_${OPENCV_MODULE_NAME}${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}")
      SET(IOS_ENTRYPOINT "__Internal")
      
      IF("${OPENCV_${OPENCV_MODULE_NAME_UPPER}_OUTPUT_NAME}" STREQUAL "")
        SET(ANDROID_ENTRYPOINT "")
        SET(MACOS_ENTRYPOINT "")
        SET(MACOS_UNITY_ENTRYPOINT "emgucv")
        SET(WINDOWS_ENTRYPOINT "")
        SET(IOS_ENTRYPOINT "")
      ENDIF()
      
      SET(ENTRYPOINT_CS_STRING "${ENTRYPOINT_CS_STRING} 
      /// <summary>
      /// The file name of the ${OPENCV_MODULE_NAME} library
      /// </summary>
      #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
      public const string Opencv${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}Library = \"${WINDOWS_ENTRYPOINT}\";
      #elif UNITY_EDITOR_OSX
      public const string Opencv${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}Library = \"${MACOS_UNITY_EDITOR_ENTRYPOINT}\";   
      #elif UNITY_STANDALONE_OSX
      public const string Opencv${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}Library = \"${MACOS_UNITY_STANDALONE_ENTRYPOINT}\";   
      #elif __IOS__ || UNITY_IPHONE || UNITY_WEBGL
      public const string Opencv${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}Library = \"${IOS_ENTRYPOINT}\";
      #elif __ANDROID__ || UNITY_ANDROID
      public const string Opencv${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}Library = \"${ANDROID_ENTRYPOINT}\";
      #else
      public const string Opencv${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}Library = \"${OPENCV_${OPENCV_MODULE_NAME_UPPER}_OUTPUT_NAME}\";
      #endif
")
    ENDIF()
  ELSE()
    IF("${OPENCV_OUTPUT_PROJ_TYPE}" STREQUAL "SHARED_LIBRARY")
      SET(ENTRYPOINT_CS_STRING "${ENTRYPOINT_CS_STRING} 
      /// <summary>
      /// The file name of the ${OPENCV_MODULE_NAME} library
      /// </summary>
      public const string Opencv${OPENCV_MODULE_NAME_FIRST_LETTER_UPPER}Library = \"${OPENCV_${OPENCV_MODULE_NAME_UPPER}_OUTPUT_NAME}\";")
    ENDIF()
  ENDIF()
  
ENDFOREACH()

SET(ENTRYPOINT_MODULES_STRING "public static List<String> OpenCVModuleList = new List<String>
	  {
#if !(__ANDROID__ || __IOS__ || UNITY_IPHONE  || UNITY_WEBGL || UNITY_ANDROID || NETFX_CORE)
        OpencvFFMpegLibrary,
#endif        
        ${ENTRYPOINT_MODULES_STRING}
        ExternLibrary
      };
")

GET_TARGET_PROPERTY(CVEXTERN_OUTPUT_NAME cvextern OUTPUT_NAME)
LIST(APPEND OPENCV_LIBRARY_OUTPUT_NAMES ${CVEXTERN_OUTPUT_NAME})

if(WIN32 AND WITH_FFMPEG)
  if(TARGET_ARCH_64)
    set(FFMPEG_SUFFIX _64)
  endif()
  #STRING(LENGTH "${OPENCV_CORE_OUTPUT_NAME}" temp)
  #MATH(EXPR temp "${temp}-3")
  #STRING(SUBSTRING ${OPENCV_CORE_OUTPUT_NAME} ${temp} -1 OPENCV_DLLVERSION)
  set(OPENCV_FFMPEG_OUTPUT_NAME "opencv_videoio_ffmpeg${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}${FFMPEG_SUFFIX}")
  #set(OPENCV_FFMPEG_OUTPUT_NAME "opencv_ffmpeg${FFMPEG_SUFFIX}")
  MESSAGE(STATUS "OPENCV_FFMPEG_OUTPUT_NAME: ${OPENCV_FFMPEG_OUTPUT_NAME}")
  LIST(APPEND OPENCV_LIBRARY_OUTPUT_NAMES ${OPENCV_FFMPEG_OUTPUT_NAME})
endif()

IF(TARGET_ARCH_64)
  SET(UNMANAGED_CODE_BITNESS "64")
ELSE()
  SET(UNMANAGED_CODE_BITNESS "32")
ENDIF()

#IF(ANDROID)
#  SET(CVINVOKE_ENTRYPOINTS_FILE_SUBFOLDER "Android/")
#ELSE()
SET(CVINVOKE_ENTRYPOINTS_FILE_SUBFOLDER "")
#ENDIF()

IF(IOS)
  SET(CVEXTERN_OUTPUT_NAME "__Internal")
ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CvInvokeEntryPoints.cs.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV/PInvoke/${CVINVOKE_ENTRYPOINTS_FILE_SUBFOLDER}CvInvokeEntryPoints.cs)

# ----------------------------------------------------------------------------
#  Build the managed dlls of Emgu CV
# ----------------------------------------------------------------------------
ADD_SUBDIRECTORY(Emgu.Util)
ADD_SUBDIRECTORY(Emgu.CV)
ADD_SUBDIRECTORY(Emgu.CV.Bitmap)
ADD_SUBDIRECTORY(Emgu.CV.Wpf)
ADD_SUBDIRECTORY(Emgu.CV.WindowsUI)

ADD_SUBDIRECTORY(Emgu.CV.Example)
ADD_SUBDIRECTORY(Emgu.CV.Test)
ADD_SUBDIRECTORY(Emgu.CV.Cuda)

ADD_SUBDIRECTORY(Emgu.CV.OCR)
 
ADD_SUBDIRECTORY(Emgu.CV.Contrib)
ADD_SUBDIRECTORY(Emgu.CV.Models)

ADD_SUBDIRECTORY(Emgu.CV.Runtime)

ADD_SUBDIRECTORY(platforms/nuget)

# MAUI will need to use some of the nuget packages. It need to be build after nuget packages is build.
ADD_SUBDIRECTORY(Emgu.CV.Runtime/Maui)

INSTALL(
  FILES
  "opencv/LICENSE"
  DESTINATION "lib"
  COMPONENT emgucv_example_source
  RENAME "opencv.license.txt"
  )    

IF(HAVE_ANDROID)
  INSTALL(
    FILES
    "Solution/Android/Emgu.CV.Android.Example.sln"
    "Solution/Android/Emgu.CV.Android.sln"
    DESTINATION "Solution/Android"
    COMPONENT emgucv_example_source
    )

ENDIF()

IF(HAVE_IOS)
  INSTALL(
    FILES
    "Solution/iOS/Emgu.CV.iOS.Example.sln"
    "Solution/iOS/Emgu.CV.iOS.Maui.sln"
    DESTINATION "Solution/iOS"
    COMPONENT emgucv_example_source
    )
ENDIF()

IF(HAVE_MACOS)
  INSTALL(
    FILES
    "Solution/Mac/Emgu.CV.Mac.Example.sln"
    DESTINATION "Solution/Mac"
    COMPONENT emgucv_example_source
    )
  IF (NOT IS_MACOS_BUILD)
    INSTALL(
      FILES
      "libs/runtimes/osx/native/libcvextern.dylib"
      DESTINATION "libs/runtimes/osx/native"
      COMPONENT emgucv_binary
      )
  ENDIF()
ENDIF()

IF(HAVE_MAC_CATALYST)
  INSTALL(
    FILES
    "Solution/Mac/Emgu.CV.Mac.Maui.sln"
    DESTINATION "Solution/Mac"
    COMPONENT emgucv_example_source
    )
  IF (HAVE_MAC_CATALYST_ARM64)
    INSTALL(
      FILES
      "libs/iOS/libcvextern_catalyst_arm64.a"
      DESTINATION "libs/iOS"
      COMPONENT emgucv_binary
      )
  ENDIF()
  IF (HAVE_MAC_CATALYST_X86_64)
    INSTALL(
      FILES
      "libs/iOS/libcvextern_catalyst_x86_64.a"
      DESTINATION "libs/iOS"
      COMPONENT emgucv_binary
      )
  ENDIF()
ENDIF()

IF (TARGET Emgu.CV.runtime.maui)
  INSTALL(
    FILES
    "Solution/CrossPlatform/Emgu.CV.CrossPlatform.sln"
	"Solution/CrossPlatform/Emgu.CV.sln"
    DESTINATION "Solution/CrossPlatform"
    COMPONENT emgucv_example_source
    )
ENDIF()

INSTALL(
  FILES
  "${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.snk"
  "${CMAKE_CURRENT_SOURCE_DIR}/CommonAssemblyInfo.cs"
  "${CMAKE_CURRENT_SOURCE_DIR}/Directory.Build.props"
  "${CMAKE_CURRENT_SOURCE_DIR}/${LICENSE_FILE_NAME}"
  DESTINATION .
  COMPONENT emgucv_source
  )
  
#IF (EMGU_CV_WITH_FREETYPE)
#  IF (ANDROID)  
	#INSTALL(EXPORT freetype DESTINATION lib)
#  ENDIF()
#ENDIF()

IF (ANDROID)
  SET(CPACK_GENERATOR ZIP)
ELSEIF (WIN32)
  SET(CPACK_GENERATOR ZIP;7Z)
  
  #IF(NETFX_CORE)
  #  SET(CPACK_GENERATOR ZIP)
  #ELSE()  
  #  SET(CPACK_GENERATOR NSIS;ZIP)
  #ENDIF()
  
  SET(CPACK_ARCHIVE_COMPONENT_INSTALL ON) #enable components install for zip
  IF(CPACK_GENERATOR MATCHES "ZIP")
    SET(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
  ENDIF()
  SET(CPACK_NSIS_MODIFY_PATH OFF)
  SET(CPACK_NSIS_INSTALL_ROOT "C:\\\\Emgu")
  
  #IF(NOT NETFX_CORE)
  #  ADD_SUBDIRECTORY(Emgu.CV.DebuggerVisualizers)
  #ENDIF()
  
  IF(NOT NETFX_CORE)
	ADD_SUBDIRECTORY(DebuggerVisualizer)
  ENDIF()

  if(WITH_FFMPEG)
    INSTALL(
  	FILES
  	"${UNMANAGED_LIBRARY_OUTPUT_PATH}/${OPENCV_FFMPEG_OUTPUT_NAME}.dll"
  	DESTINATION "libs/${UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER}/"
  	COMPONENT libs
  	)
  endif()
  
  # ----------------------------------------------------------------------------
  #  Build the documents of Emgu CV
  # ----------------------------------------------------------------------------
  SET(EMGU_CV_DOCUMENTATION_BUILD OFF CACHE BOOL "Build Emgu CV Documentation")
  IF(EMGU_CV_DOCUMENTATION_BUILD)
    ADD_SUBDIRECTORY(miscellaneous)
  ENDIF()

  # ----------------------------------------------------------------------------
  #  Set if we should sign the managed assembly
  # ----------------------------------------------------------------------------  
  IF (WIN32)
	SET(EMGU_SIGN_ASSEMBLY OFF CACHE BOOL "If enabled, we will sign the managed assembly")
  ELSE()
	SET(EMGU_SIGN_ASSEMBLY ON CACHE BOOL "If enabled, we will sign the managed assembly")
  ENDIF()
  
  # ----------------------------------------------------------------------------
  #  Build the extra components of Emgu CV
  # ----------------------------------------------------------------------------
  SET(EMGU_CV_EXTRA_BUILD OFF CACHE BOOL "Build Emgu CV Extra")
  IF(EMGU_CV_EXTRA_BUILD)
    ADD_SUBDIRECTORY(Emgu.RPC)
  ENDIF()
  
#  # ----------------------------------------------------------------------------
#  #  The source files
#  # ----------------------------------------------------------------------------
#  INSTALL(
#    DIRECTORY
#    ${CMAKE_CURRENT_SOURCE_DIR}/lib
#    DESTINATION .
#    COMPONENT emgucv_source
#    FILES_MATCHING 
#    PATTERN "*.dll"
#    PATTERN "*.txt"
#    PATTERN "*.xml"
#    PATTERN ".git" EXCLUDE
#    PATTERN "obj" EXCLUDE
#    PATTERN "CMake*" EXCLUDE
#    PATTERN "Release" EXCLUDE
#    PATTERN "${PROJECT_NAME}.dir" EXCLUDE
#    )
	
  # ----------------------------------------------------------------------------
  #  Include the version_str.inc files in the package
  # ----------------------------------------------------------------------------
  INSTALL(
    DIRECTORY
    ${CMAKE_CURRENT_SOURCE_DIR}/libs
    DESTINATION .
    COMPONENT emgucv_binary
    FILES_MATCHING 
    PATTERN "*version_string.inc"
    PATTERN ".git" EXCLUDE
    PATTERN "obj" EXCLUDE
    PATTERN "CMake*" EXCLUDE
    )
  
  #WINDOWS STORE EXAMPLE
  IF(HAVE_WINSTORE_10_X86 OR HAVE_WINSTORE_10_X64 OR HAVE_WINSTORE_10_ARM)  
    INSTALL(
      DIRECTORY
      ${CMAKE_CURRENT_SOURCE_DIR}/Solution
      DESTINATION .
      COMPONENT emgucv_example_source
      FILES_MATCHING 
      PATTERN "Emgu.CV.Example.Windows.UWP.sln"
	  PATTERN "Windows.UWP/packages/repositories.config"
      PATTERN ".git" EXCLUDE
      PATTERN "bin" EXCLUDE
      PATTERN "Android" EXCLUDE
      PATTERN "iOS" EXCLUDE
      PATTERN "Windows.Phone" EXCLUDE
      PATTERN "Windows.Desktop" EXCLUDE
      PATTERN "CrossPlatform" EXCLUDE
	  PATTERN "Mac" EXCLUDE
      )
  ENDIF()
  
  #WIN32 and not NETFX_CORE solution files
  IF (HAVE_WINDESKTOP_X86 OR HAVE_WINDESKTOP_X64 OR HAVE_WINDESKTOP_ARM64)
    INSTALL(
      DIRECTORY
      ${CMAKE_CURRENT_SOURCE_DIR}/Solution
      DESTINATION .
      COMPONENT emgucv_source
      FILES_MATCHING 
      PATTERN "Emgu.CV.sln"
      PATTERN "Emgu.CV.DebuggerVisualizers.sln"
      PATTERN ".git" EXCLUDE
      PATTERN "bin" EXCLUDE
      PATTERN "Android" EXCLUDE
      PATTERN "iOS" EXCLUDE
      PATTERN "CrossPlatform" EXCLUDE
	  PATTERN "Mac" EXCLUDE
	  PATTERN "Windows.UWP" EXCLUDE
      )
    INSTALL(
      DIRECTORY
      ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.WPF
      DESTINATION .
      COMPONENT emgucv_example_source
      FILES_MATCHING 
      PATTERN "*.cs"
      PATTERN ".git" EXCLUDE
      )
    INSTALL(
      DIRECTORY
      ${CMAKE_CURRENT_SOURCE_DIR}/Solution
      DESTINATION .
      COMPONENT emgucv_example_source
      FILES_MATCHING 
      PATTERN "Emgu.CV.Example.sln"
      PATTERN ".git" EXCLUDE
      PATTERN "bin" EXCLUDE
      PATTERN "Android" EXCLUDE
      PATTERN "iOS" EXCLUDE
      PATTERN "Windows.UWP" EXCLUDE
      PATTERN "CrossPlatform" EXCLUDE
	  PATTERN "Mac" EXCLUDE
      )
    
    # ----------------------------------------------------------------------------
    #  The example files
    # ----------------------------------------------------------------------------
    # INSTALL(
      # DIRECTORY
      # ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Example
      # DESTINATION .
      # COMPONENT emgucv_example_source
      # FILES_MATCHING 
      # PATTERN "*.cs"
      # PATTERN "*.csproj"
      # PATTERN "*.resx"
      # PATTERN "*.h"
      # PATTERN "*.cpp"
      # PATTERN "*.resX"
      # PATTERN "*.ico"
      # PATTERN "*.rc"
      # PATTERN "CPlusPlus/*.vcproj"
      # PATTERN "CPlusPlus/*.vcxproj"
      # PATTERN "*.vb"
      # PATTERN "*.vbproj"
      # PATTERN "*.aspx" 
      # PATTERN "*.dll"
      # PATTERN "*.txt"
      # PATTERN "*.xml"
      # PATTERN "*.xaml"
      # PATTERN "*.jpg"
      # PATTERN "*.png"
	  # PATTERN "*.svg"
      # PATTERN "*.settings"
      # PATTERN "*.config"
      # PATTERN "tessdata/*"
      # PATTERN ".git" EXCLUDE
      # PATTERN "obj" EXCLUDE
      # PATTERN "CMake*" EXCLUDE
      # PATTERN "Release" EXCLUDE
      # PATTERN "Debug" EXCLUDE
      # PATTERN "RelWithDebInfo" EXCLUDE
      # PATTERN "*.dir" EXCLUDE
      # PATTERN "Android" EXCLUDE
      # PATTERN "iOS" EXCLUDE
      # PATTERN "Mac" EXCLUDE
      # PATTERN "WindowsStore" EXCLUDE
      # PATTERN "WindowsPhoneApp" EXCLUDE
      # PATTERN "WindowsStoreCameraApp" EXCLUDE
      # )
  ENDIF()
  
  INSTALL(
    FILES
    "${OPENCV_SUBFOLDER}/data/haarcascades/haarcascade_frontalface_default.xml"
    "${OPENCV_SUBFOLDER}/data/haarcascades/haarcascade_eye.xml"
    DESTINATION opencv/data/haarcascades
    COMPONENT emgucv_example_source
    )
  INSTALL(
    FILES
    "${OPENCV_CONTRIB_SUBFOLDER}/modules/text/samples/trained_classifierNM1.xml"
    "${OPENCV_CONTRIB_SUBFOLDER}/modules/text/samples/trained_classifierNM2.xml"
    "${OPENCV_CONTRIB_SUBFOLDER}/modules/text/samples/trained_classifier_erGrouping.xml"
    DESTINATION opencv_contrib/modules/text/samples/
    COMPONENT emgucv_example_source
    ) 
  
  # ----------------------------------------------------------------------------
  #  Build the package
  # ----------------------------------------------------------------------------
  
  set(CPACK_COMPONENTS_ALL 
    libs #opencv components 
    emgucv_binary 
    emgucv_source
    emgucv_example_source
    )
  
  set(CPACK_PACKAGE_EXECUTABLES "" "") #http://public.kitware.com/Bug/view.php?id=7828
  
  SET(CPACK_NSIS_CONTACT "support@emgu.com")
  
  # Define MUI_TEMP that will be used for uninstalling menulinks
  SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\n !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP")
  
  # ----------------------------------------------------------------------------
  #  Add menu link for documentations
  # ----------------------------------------------------------------------------
  SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateDirectory \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation\\\" ")
  
  #SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation\\\\Open CV Documentation.lnk\\\"  \\\"$INSTDIR\\\\doc\\\\opencv2refman.pdf\\\" ")	
  #SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\n Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation\\\\Open CV Documentation.lnk\\\" ")
  
  IF(EMGU_CV_DOCUMENTATION_BUILD)
    LIST(APPEND CPACK_COMPONENTS_ALL emgucv_document)
    set(CPACK_COMPONENT_EMGUCV_DOCUMENT_DISPLAY_NAME "Emgu CV Documentation")
    set(CPACK_COMPONENT_EMGUCV_DOCUMENT_DEPENDS emgucv_binary)
    SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation\\\\Emgu CV Documentation.lnk\\\"  \\\"$INSTDIR\\\\Emgu.CV.Documentation.chm\\\" ")	
    SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\n Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation\\\\Emgu CV Documentation.lnk\\\" ")
  ENDIF()
  
  SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\nRMDir  \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation\\\" ")
  
  # ----------------------------------------------------------------------------
  #  Add menu link for web sites
  # ----------------------------------------------------------------------------
  LIST(APPEND CPACK_NSIS_MENU_LINKS "https://www.emgu.com" "Emgu CV wiki")
  LIST(APPEND CPACK_NSIS_MENU_LINKS "${GITHUB_REPO_URL}/discussions" "Discussions")
  LIST(APPEND CPACK_NSIS_MENU_LINKS "${GITHUB_REPO_URL}/issues" "Issues Tracking")
  
  # ----------------------------------------------------------------------------
  #  Add menu link for Visual Studio solutions 
  # ----------------------------------------------------------------------------
  SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateDirectory \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Visual Studio Solution\\\" ")
  
  SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Visual Studio Solution\\\\Visual Studio 2017 - 2022 Examples.lnk\\\"  \\\"$INSTDIR\\\\Solution\\\\Windows.Desktop\\\\Emgu.CV.Example.sln\\\" ")	
  
  SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\n Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Visual Studio Solution\\\\Visual Studio 2017 - 2022 Examples.lnk\\\" ")
  
  SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\nRMDir  \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Visual Studio Solution\\\" ")
  
  # ----------------------------------------------------------------------------
  #  Add menu link for Licenses 
  # ----------------------------------------------------------------------------
  SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateDirectory \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\License\\\" ")
  
  SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\License\\\\Emgu CV License.lnk\\\"  \\\"$INSTDIR\\\\${LICENSE_FILE_NAME}\\\" ")	
  SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\License\\\\Open CV License.lnk\\\"  \\\"$INSTDIR\\\\lib\\\\opencv.license.txt\\\" ")
  IF(EMGU_CV_WITH_TESSERACT)
    SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\License\\\\Tesseract OCR License.lnk\\\"  \\\"$INSTDIR\\\\lib\\\\tesseract-ocr.license.txt\\\" ")	
  ENDIF()
  #SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}\nCreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\License\\\\CvBlob License.lnk\\\"  \\\"$INSTDIR\\\\lib\\\\3rdParty\\\\cvblob.license.txt\\\" ")	
  
  SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\n Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\License\\\\Emgu CV License.lnk\\\" ")
  SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\n Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\License\\\\Open CV License.lnk\\\" ")
  IF(EMGU_CV_WITH_TESSERACT)
    SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\n Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\License\\\\Tesseract OCR License.lnk\\\" ")
  ENDIF()
  #SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\n Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\License\\\\CvBlob License.lnk\\\" ")
  SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}\nRMDir  \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\License\\\" ")
  
  #IF(EMGU_CV_EXAMPLE_BUILD AND NOT NETFX_CORE)
  #  LIST(APPEND CPACK_COMPONENTS_ALL emgucv_example_binary)
  #  SET(CPACK_COMPONENT_EMGUCV_EXAMPLE_BINARY_DISPLAY_NAME "Emgu CV Examples (Binary)")
  #  SET(CPACK_COMPONENT_EMGUCV_EXAMPLE_BINARY_DEPENDS emgucv_binary)
  #ENDIF()
  
  set(CPACK_COMPONENT_MAIN_DISPLAY_NAME "OpenCV Native Binary")
  set(CPACK_COMPONENT_MAIN_REQUIRED ON)
  set(CPACK_COMPONENT_EMGUCV_BINARY_DISPLAY_NAME "Emgu CV (Binary)")
  set(CPACK_COMPONENT_EMGUCV_BINARY_REQUIRED ON)
  set(CPACK_COMPONENT_EMGUCV_BINARY_DEPENDS libs)
  set(CPACK_COMPONENT_EMGUCV_SOURCE_DISPLAY_NAME "Emgu CV (Source)")
  set(CPACK_COMPONENT_EMGUCV_SOURCE_DEPENDS libs)
  set(CPACK_COMPONENT_EMGUCV_EXAMPLE_SOURCE_DISPLAY_NAME "Emgu CV Examples (Source)")
  set(CPACK_COMPONENT_EMGUCV_EXAMPLE_SOURCE_DEPENDS emgucv_source)
  
  
  IF (${CMAKE_VERSION} VERSION_GREATER "3.19.0" AND WIN32)
    STRING(REGEX REPLACE "/" "\\\\\\\\" WIN_CMAKE_COMMAND "${CMAKE_COMMAND}" )
	
    IF(EMGU_SIGN_FOUND)
	  #Sign the windows installer (.exe)
	  SET(NSIS_PACKAGE_FILE ${CMAKE_BINARY_DIR}/lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.exe)
      #MESSAGE(STATUS "CPACK_PACKAGE_FILES: ${NSIS_PACKAGE_FILE}")  
	  STRING(REGEX REPLACE "/" "\\\\\\\\" WIN_EMGU_SIGN_EXECUTABLE "${EMGU_SIGN_EXECUTABLE}")
	  STRING(REGEX REPLACE "/" "\\\\\\\\" WIN_PACKAGE_FILE "${CMAKE_BINARY_DIR}/lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.exe")
	  STRING(REGEX REPLACE "/" "\\\\\\\\" WIN_PACKAGE_FOLDER "${CMAKE_BINARY_DIR}/signed")
	  STRING(REGEX REPLACE "/" "\\\\\\\\" WIN_SIGNTOOL_EXECUTABLE "${SIGNTOOL_EXECUTABLE}")
	  #FILE(WRITE "${CMAKE_BINARY_DIR}/sign_package.txt" "add_custom_command(OUTPUT ${WIN_PACKAGE_FOLDER}/lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.exe\n")
	  FILE(WRITE "${CMAKE_BINARY_DIR}/sign_package.cmake" "IF(EXISTS \"${CMAKE_BINARY_DIR}/lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.exe\")\n")
	  FILE(APPEND "${CMAKE_BINARY_DIR}/sign_package.cmake" "  FILE(MAKE_DIRECTORY \"${CMAKE_BINARY_DIR}/signed\")\n")
	  #FILE(APPEND "${CMAKE_BINARY_DIR}/sign_package.cmake" "  EXECUTE_PROCESS(COMMAND \"${WIN_CMAKE_COMMAND}\" -E make_directory \"${CMAKE_BINARY_DIR}/signed\")\n")
	  FILE(APPEND "${CMAKE_BINARY_DIR}/sign_package.cmake" "  EXECUTE_PROCESS(COMMAND \"${WIN_EMGU_SIGN_EXECUTABLE}\" \"${WIN_PACKAGE_FILE}\" \"${WIN_PACKAGE_FOLDER}\" \"${WIN_SIGNTOOL_EXECUTABLE}\")\n")
	  FILE(APPEND "${CMAKE_BINARY_DIR}/sign_package.cmake" "ENDIF()\n")
      LIST(APPEND CPACK_POST_BUILD_SCRIPTS "${CMAKE_BINARY_DIR}/sign_package.cmake")
	  #LIST(APPEND CPACK_POST_BUILD_SCRIPTS "${WIN_EMGU_SIGN_EXECUTABLE} ${CMAKE_BINARY_DIR}/lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.exe ${CMAKE_BINARY_DIR}/signed")
	ENDIF()
	
	IF (WITH_CUDA)
		FIND_PROGRAM (SEVEN_ZIP_EXECUTABLE
			NAMES 7z 
			PATHS
			$ENV{programfiles}/7-Zip
			CMAKE_FIND_ROOT_PATH_BOTH
			)
			
		IF (SEVEN_ZIP_EXECUTABLE)
		  MESSAGE(STATUS "Found 7z.exe: ${SEVEN_ZIP_EXECUTABLE}")
		  STRING(REGEX REPLACE "/" "\\\\\\\\" WIN_PACKAGE_ZIP_FILE "${CMAKE_BINARY_DIR}/lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.zip")
		  STRING(REGEX REPLACE "/" "\\\\\\\\" WIN_SEVEN_ZIP_EXECUTABLE "${SEVEN_ZIP_EXECUTABLE}")
		  FILE(WRITE "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake" "EXECUTE_PROCESS(COMMAND echo \\\\${CPACK_PACKAGE_FILES})\n")
		  FILE(APPEND "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake" "IF (EXISTS \"${CMAKE_BINARY_DIR}/lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.zip\")\n")
		  FILE(APPEND "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake" "  EXECUTE_PROCESS(COMMAND \"${WIN_CMAKE_COMMAND}\" -E rm -rf \"${CMAKE_BINARY_DIR}/lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}\")\n")
		  FILE(APPEND "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake" "  EXECUTE_PROCESS(COMMAND \"${WIN_CMAKE_COMMAND}\" -E rm -f \"${WIN_PACKAGE_ZIP_FILE}.selfextract.exe\")\n")
		  FILE(APPEND "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake" "  EXECUTE_PROCESS(COMMAND \"${WIN_CMAKE_COMMAND}\" -E make_directory \"${CMAKE_BINARY_DIR}/lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}\")\n")
		  FILE(APPEND "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake" "  EXECUTE_PROCESS(COMMAND \"${WIN_SEVEN_ZIP_EXECUTABLE}\" x \"${WIN_PACKAGE_ZIP_FILE}\" -olib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION} -y)\n")
		  FILE(APPEND "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake" "  EXECUTE_PROCESS(COMMAND \"${WIN_SEVEN_ZIP_EXECUTABLE}\" a -sfx7z.sfx \"${WIN_PACKAGE_ZIP_FILE}.selfextract.exe\" lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION} -mx=9 -m0=LZMA2 -mmt=off -md=512m )\n")
		  
		  IF (EMGU_SIGN_FOUND)
			FILE(APPEND "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake" "  EXECUTE_PROCESS(COMMAND \"${WIN_EMGU_SIGN_EXECUTABLE}\" \"${WIN_PACKAGE_ZIP_FILE}.selfextract.exe\" \"${WIN_PACKAGE_FOLDER}\" \"${WIN_SIGNTOOL_EXECUTABLE}\")\n")
		  ENDIF()
		  
		  FILE(APPEND "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake" "ENDIF()\n")
		  LIST(APPEND CPACK_POST_BUILD_SCRIPTS "${CMAKE_BINARY_DIR}/convert_to_7zip.cmake")
		ENDIF()
	ENDIF()

  ENDIF()
 
  
ELSEIF (APPLE)
  
  SET(CPACK_GENERATOR ZIP)
  SET(CPACK_BUNDLE_NAME ${CPACK_PACKAGE_NAME})
  
  SET(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/platforms/macos/icons.icns")
  IF (IOS)
    SET(CPACK_ARCHIVE_COMPONENT_INSTALL ON) #enable components install for zip
    IF(CPACK_GENERATOR MATCHES "ZIP")
      SET(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
    ENDIF()
    set(CPACK_COMPONENTS_ALL emgucv_binary emgucv_source emgucv_example_source)
  ENDIF()

  # ----------------------------------------------------------------------------
  #  The source files
  # ----------------------------------------------------------------------------
  
  INSTALL(
    DIRECTORY
    ${CMAKE_CURRENT_SOURCE_DIR}/lib
    DESTINATION .
    COMPONENT emgucv_source
    FILES_MATCHING 
    PATTERN "*.dll"
    PATTERN "*.txt"
    PATTERN "*.xml"
    PATTERN ".git" EXCLUDE
    PATTERN "obj" EXCLUDE
    PATTERN "CMake*" EXCLUDE
    PATTERN "Release" EXCLUDE
    PATTERN "${PROJECT_NAME}.dir" EXCLUDE
    )

  
  # ----------------------------------------------------------------------------
  #  The example files
  # ----------------------------------------------------------------------------
  INSTALL(
    DIRECTORY
    ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.CV.Example
    DESTINATION .
    COMPONENT emgucv_example_source
    FILES_MATCHING 
    PATTERN "*.cs"
    PATTERN "*.csproj"
    PATTERN "*.resx"
    PATTERN "*.h"
    PATTERN "*.cpp"
    PATTERN "*.resX"
    PATTERN "*.ico"
    PATTERN "*.rc"
    PATTERN "CPlusPlus/*.vcproj"
    PATTERN "CPlusPlus/*.vcxproj"
    PATTERN "*.vb"
    PATTERN "*.vbproj"
    PATTERN "*.aspx" 
    PATTERN "*.dll"
    PATTERN "*.txt"
    PATTERN "*.xml"
    PATTERN "*.xaml"
    PATTERN "*.jpg"
    PATTERN "*.png"  
    PATTERN "*.settings"
    PATTERN "*.config"
    PATTERN "tessdata/*"
    PATTERN ".git" EXCLUDE
    PATTERN "obj" EXCLUDE
    PATTERN "CMake*" EXCLUDE
    PATTERN "Release" EXCLUDE
    PATTERN "Debug" EXCLUDE
    PATTERN "*.dir" EXCLUDE
    PATTERN "Android" EXCLUDE
    PATTERN "iOS" EXCLUDE
    )
  
  INSTALL(
    FILES
    "${OPENCV_SUBFOLDER}/data/haarcascades/haarcascade_frontalface_default.xml"
    "${OPENCV_SUBFOLDER}/data/haarcascades/haarcascade_eye.xml"
    DESTINATION opencv/data/haarcascades
    COMPONENT emgucv_example_source
    )
  
  INSTALL(
    FILES
    "${OPENCV_CONTRIB_SUBFOLDER}/modules/text/samples/trained_classifierNM1.xml"
    "${OPENCV_CONTRIB_SUBFOLDER}/modules/text/samples/trained_classifierNM2.xml"
    "${OPENCV_CONTRIB_SUBFOLDER}/modules/text/samples/trained_classifier_erGrouping.xml"
    DESTINATION opencv_contrib/modules/text/samples/
    COMPONENT emgucv_example_source
    )
  
  
  # ----------------------------------------------------------------------------
  #  Generate required common assembly file for Emgu CV project
  # ----------------------------------------------------------------------------
  SET(CPACK_BUNDLE_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos/Info.plist)
  FILE(WRITE ${CPACK_BUNDLE_PLIST}
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
   <key>CFBundleIdentifier</key>
   <string>com.emgu.cv</string>
   <key>CFBundleName</key>
   <string>${CPACK_BUNDLE_NAME}</string>
   <key>CFBundleVersion</key>
   <string>1</string>
   <key>LSMinimumSystemVersion</key>
   <string>10.6</string>
</dict>
</plist>")
  
ELSE() #LINUX
  SET(MONO_GACUTIL_EXEC "gacutil")
  #SET(LINUX_CONTROL_FILE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/cmake/linux")
  SET(EMGUCV_MANAGED_DLLS "Emgu.CV")
  
  #SET(CLIFILELIST_CONTENT "")
  #FOREACH(MANAGED_DLL ${EMGUCV_MANAGED_DLLS})
  #  SET(CLIFILELIST_CONTENT "${CLIFILELIST_CONTENT}/usr/${CPACK_PACKAGE_CLI_FOLDER}/${MANAGED_DLL}.dll\n")
  #ENDFOREACH()
  #FILE(WRITE ${LINUX_CONTROL_FILE_FOLDER}/clifilelist.txt ${CLIFILELIST_CONTENT})
  #INSTALL(
  #  FILES
  #  ${LINUX_CONTROL_FILE_FOLDER}/clifilelist.txt
  #  DESTINATION ${CPACK_PACKAGE_CLI_FOLDER}
  #  COMPONENT emgucv_binary)
  
  #creating the pkg-config file
  #SET(PACKAGE_CFG_REF_CONTENT "")
  #FOREACH(MANAGED_DLL ${EMGUCV_MANAGED_DLLS})
  #  SET(PACKAGE_CFG_REF_CONTENT "${PACKAGE_CFG_REF_CONTENT} -r:\${libdir}/${MANAGED_DLL}.dll")
  #ENDFOREACH()
  
  #FILE(WRITE ${LINUX_CONTROL_FILE_FOLDER}/${CPACK_PACKAGE_NAME}.pc
  #  "prefix=/usr\nexec_prefix=\${prefix}\nlibdir=\${exec_prefix}/${CPACK_PACKAGE_CLI_FOLDER}\napidir=\${exec_prefix}/${CPACK_PACKAGE_CLI_FOLDER}\n\nName: ${CPACK_PACKAGE_NAME}\nDescription: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}\nVersion: ${CPACK_PACKAGE_VERSION}\nLibs: ${PACKAGE_CFG_REF_CONTENT}\n")
  #INSTALL(
  #  FILES
  #  ${LINUX_CONTROL_FILE_FOLDER}/${CPACK_PACKAGE_NAME}.pc
  #  DESTINATION /usr/lib/pkgconfig
  #  COMPONENT emgucv_binary)
  
  #SET(REMOVE_EMGU_FROM_GAC_SCRIPT "")
  #FOREACH(MANAGED_DLL ${EMGUCV_MANAGED_DLLS})
  #  SET(REMOVE_EMGU_FROM_GAC_SCRIPT "${REMOVE_EMGU_FROM_GAC_SCRIPT} ${MANAGED_DLL}")
  #ENDFOREACH()
  #SET(REMOVE_EMGU_FROM_GAC_SCRIPT "for dll in${REMOVE_EMGU_FROM_GAC_SCRIPT}; do ${MONO_GACUTIL_EXEC} -u $dll; done")
  
  #SET(CPACK_STRIP_FILES "")
  
  IF(NOT CPACK_GENERATOR)
    MESSAGE(STATUS "Checking for CPACK build type...")
    FIND_PROGRAM(ZIP_CMD zip)
    IF (ZIP_CMD)
      # ----------------------------------------------------------------------------
      #  Building .deb package for Debian 
      # ----------------------------------------------------------------------------
      MESSAGE(STATUS "FOUND zip: ${ZIP_CMD}")
      LIST(APPEND CPACK_GENERATOR ZIP)
    ENDIF()

    #FIND_PROGRAM(DPKG_CMD dpkg)
    #IF (DPKG_CMD)
      # ----------------------------------------------------------------------------
      #  Building .deb package for Debian 
      # ----------------------------------------------------------------------------
    #  MESSAGE(STATUS "FOUND dpkg: ${DPKG_CMD}")
    #  LIST(APPEND CPACK_GENERATOR DEB)
    #ENDIF()
    
    #FIND_PROGRAM(RPMBUILD_CMD rpmbuild)
    #IF(RPMBUILD_CMD)
      # ----------------------------------------------------------------------------
      #  Building .rpm package  
      # ----------------------------------------------------------------------------
    #  MESSAGE(STATUS "FOUND rpmbuild: ${RPMBUILD_CMD}")
    #  LIST(APPEND CPACK_GENERATOR RPM)
    #ENDIF()
  ENDIF()
  
  #SET(PREINST_SCRIPT "#!/bin/sh\nmkdir -p /usr/lib/pkgconfig /usr/${CPACK_PACKAGE_CLI_FOLDER} /usr/share/opencv/haarcascades /usr/share/opencv/lbpcascades /usr/share/opencv/doc \n")
  #LIST(FIND CPACK_GENERATOR "DEB" TEMP)
  #IF(NOT (${TEMP} EQUAL -1))
  #  SET(DEBIAN_CONTROL_FILE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/cmake/debian")
  #  FILE(WRITE ${DEBIAN_CONTROL_FILE_FOLDER}/preinst ${PREINST_SCRIPT}) 
  #  FILE(WRITE ${DEBIAN_CONTROL_FILE_FOLDER}/postinst
  #    "#!/bin/sh\nset -e\nif [ \"$1\" = \"configure\" ]; then\n  ldconfig\n  ${MONO_GACUTIL_EXEC} -il /usr/${CPACK_PACKAGE_CLI_FOLDER}/clifilelist.txt -package ${CPACK_PACKAGE_NAME}\nfi\n")
  #  FILE(WRITE ${DEBIAN_CONTROL_FILE_FOLDER}/prerm
  #    "#!/bin/sh\nset -e\nif [ \"$1\" = \"remove\" ] || [ \"$1\" = \"upgrade\" ] && [ -x /usr/share/cli-common/gac-package-remove ]; then\n${REMOVE_EMGU_FROM_GAC_SCRIPT}\nfi\n")
    
  #  SET(DEBIAN_PACKAGE_PRIORITY "optional")
  #  SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${DEBIAN_CONTROL_FILE_FOLDER}/preinst;${DEBIAN_CONTROL_FILE_FOLDER}/postinst;${DEBIAN_CONTROL_FILE_FOLDER}/prerm;${DEBIAN_CONTROL_FILE_FOLDER}/postrm")
  #  SET(CPACK_DEBIAN_PACKAGE_DEPENDS "mono-runtime (>> 2.4.2), mono-2.0-gac, libtiff5, libgeotiff2, libgtk-3-0, libgstreamer1.0-0, libavcodec54, libswscale2, libavformat54, libopenexr6, libjasper1, libdc1394-22, libv4l-0, libqt4-opengl")
  #  IF(EMGU_CV_WITH_TESSERACT)
  #    SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libtesseract3")
  #  ENDIF()
  #  IF(WITH_TBB)
  #    SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libtbb2")
  #  ENDIF()
  #ENDIF()
  
  #LIST(FIND CPACK_GENERATOR "RPM" TEMP)
  #IF(NOT (${TEMP} EQUAL -1))  
  #  SET(CPACK_RPM_PACKAGE_LICENSE "GPL v3")
  #  SET(CPACK_RPM_PACKAGE_REQUIRES "mono-core >= 2.6, mono-wcf, jasper, libgeotiff, gtk2, OpenEXR, libv4l, libdc1394, qt")
  #  IF (WITH_TBB)
  #    SET(CPACK_RPM_PACKAGE_REQUIRES ", tbb")
  #  ENDIF()
  #  IF(EMGUCV_WITH_TESSERACT AND TESSERACT_FOUND)
  #    SET(CPACK_RPM_PACKAGE_REQUIRES ", tesseract")
  #  ENDIF()    
  #  SET(RPM_CONTROL_FILE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/cmake/rpm")
  #  FILE(WRITE ${RPM_CONTROL_FILE_FOLDER}/preinst ${PREINST_SCRIPT})
  #  FILE(WRITE ${RPM_CONTROL_FILE_FOLDER}/postinst
  #    "ldconfig\n${MONO_GACUTIL_EXEC} -il /usr/${CPACK_PACKAGE_CLI_FOLDER}/clifilelist.txt -package ${CPACK_PACKAGE_NAME}\n")
  #  FILE(WRITE ${RPM_CONTROL_FILE_FOLDER}/prerm
  #    "${REMOVE_EMGU_FROM_GAC_SCRIPT}\n")
  #  SET(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${RPM_CONTROL_FILE_FOLDER}/preinst")
  #  SET(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${RPM_CONTROL_FILE_FOLDER}/postinst")
  #  SET(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${RPM_CONTROL_FILE_FOLDER}/prerm")
  #  SET(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${RPM_CONTROL_FILE_FOLDER}/postrm")
  #ENDIF()	
ENDIF()  

MESSAGE(STATUS "CPACK_GENERATOR: ${CPACK_GENERATOR}")
INCLUDE (CPack) 
